<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <!--
           <div class="layui-form lay-header">
               <div class="toolbar">
                   <div class="layui-form-item lay-query-content">

                       <div class="lay-query-box">
                           <div class="query-lt">

                               <div class="layui-inline">
                                   <label class="layui-form-label w-auto">柜子类型：</label>
                                   <div class="layui-input-inline">
                                       <select id="toolCabinetType" name="toolCabinetType">
                                           <option value="">柜子类型</option>
                                       </select>
                                   </div>
                               </div>
                               <div class="layui-inline">
                                   <label class="layui-form-label w-auto">渠道品牌：</label>
                                   <div class="layui-input-inline">
                                       <select id="channelBrand" name="channelBrand">
                                           <option value="">渠道品牌</option>
                                       </select>
                                   </div>
                               </div>

                               <div class="layui-inline">
                                   <label class="layui-form-label w-auto">设备状态：</label>
                                   <div class="layui-input-inline">
                                       <select name="equipmentStatus">
                                           <option value="">设备状态</option>
                                           <option value="富兰地">启用</option>
                                           <option value="株砖">禁用</option>
                                       </select>
                                   </div>
                               </div>
                               <div class="layui-inline">
                                   <label class="layui-form-label w-auto">按车间：</label>
                                   <div class="layui-input-inline">
                                       <select name="channelBrand">
                                           <option value="">按车间</option>
                                       </select>
                                   </div>
                               </div>

                               <div class="layui-inline">
                                   <label class="layui-form-label w-auto">柜子编号：</label>
                                   <div class="layui-input-inline">
                                       <input type="text" class="layui-input" placeholder="柜子编号" name="username">
                                   </div>
                               </div>
                               <div class="layui-inline">
                                   <label class="layui-form-label w-auto">企业名称：</label>
                                   <div class="layui-input-inline">
                                       <input type="text" class="layui-input" placeholder="客户企业名称" name="">
                                   </div>
                               </div>

                           </div>
                           <div class="query-rt">
                               <div class="layui-inline">
                                   <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog"
                                           lay-submit>查询
                                   </button>
                                   <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置
                                   </button>
                               </div>
                           </div>
                       </div>

                   </div>
               </div>
           </div>
            -->
            <!-- 接入称重柜表格 -->
            <table class="layui-table" id="toolCabinetTable" lay-filter="toolCabinetTable"></table>
        </div>
    </div>
</div>

<style>
    .width105 {
        width: 105px;
    }

    .layui-table-cell {
        height: auto;
        max-height: 80px;
    }

    .cargoLanelModifyForm label {
        width: 120px;
    }

    .borderNone {
        border: none;
    }
    form[lay-filter="addPermissionGroupMembersForm"] label{
        padding: 9px;
        width: 90px;
    }
    xm-select{
        width: 99%;
    }
    form.layui-form.model-form.mainCabinetAuthorityForm {
        padding: 10px 20px 0 20px;
        height: calc(100% - 25px);
        overflow: hidden;
    }
    .mainCabinetAuthorityForm .open-details-box {
        height: calc(100% - 100px);
        overflow: auto;
    }
    .mainCabinetAuthorityForm label{
        width: auto;
        padding: 9px 0;
    }
    form[lay-filter="addPermissionsGroupForm"] label {
        padding: 9px;
        width: 115px;
    }
    .colorBlack{
        padding-right: 15px;
        color: var(--color1);
        font-weight: 600;
    }
    .colorBlack1{
        padding-right: 15px;
    }
    .addPermissionGroupMembersDetail{
        display: none;
    }
</style>
<script type="text/html" id="toolCabinetTableBar">
    <a class="layui-btn  layui-btn-xs" lay-event="details">详情</a>
    <!-- <a class="layui-btn  layui-btn-xs" lay-event="">管理员</a> -->

    {{# if(d.cabinetNature =='main'){  }}
    <a class="layui-btn  layui-btn-xs" lay-event="permissionsBtn">权限</a>
    {{# } }}

    {{# if(d.cabinetNature == "sale"){  }}
    <a class="layui-btn  layui-btn-xs" lay-event="cargoLaneBtn">货位</a>
    {{# }else if(d.cabinetNature == "live"){ }}
    <!--
    <a class="layui-btn  layui-btn-xs" lay-event="temporaryStorageCabinetBtn">暂存柜</a>
    -->
    {{# }else{ }}
    <a class="layui-btn  layui-btn-xs" lay-event="cargoLaneBtn">货位</a>
    <!--
    <a class="layui-btn  layui-btn-xs" lay-event="temporaryStorageCabinetBtn">暂存柜</a>
    -->
    {{# } }}


    <a class="layui-btn  layui-btn-xs" lay-event="productBtn">物料</a>
    <a class="layui-btn  layui-btn-xs" lay-event="orderBtn">订单</a>
    <!-- <a class="layui-btn  layui-btn-xs" lay-event="">+辅柜</a>
    <a class="layui-btn  layui-btn-xs" lay-event="">报表</a>
    <a class="layui-btn  layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
    -->
    <a class="layui-btn  layui-btn-xs" lay-event="modifyBtn">修改</a>
    {{# if(d.cabinetNature == "main"){  }}

    {{# } }}
</script>
<!-- 修改 -->
<script type="text/html" id="companyForm">
    <form lay-filter="companyForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red"></span>企业自定义名称</label>
            <div class="layui-input-block">
                <input name="cabName" placeholder="请输入企业自定义名称" type="text" class="layui-input"
                       lay-verify="" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: #ff0000">*</span>所属企业</label>
            <div class="layui-input-block">
                <select name="settledCompanyId" lay-filter="getCompanyInfo" lay-verify="required" required
                        lay-search></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>客户所在地</label>
            <div class="layui-input-block">
                <input name="workshopLocation" placeholder="请输入所在地区" type="text" class="layui-input"
                       lay-verify="required" required/>
            </div>
        </div>

        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="companyFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>
<!-- 添加设备(详情) -->
<script type="text/html" id="adddevicePopup">
    <form lay-filter="adddevicePopupForm" class="layui-form model-form">
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span> 所属服务商</label>
            <div class="layui-input-inline ">
                <select name="name" lay-filter="aihao">
                    <option value="">请选择</option>
                    <option value="1">湖南云端商业管理有限公司</option>
                    <option value="2">湖南很好的代理渠道有限公司</option>
                </select>
            </div>
        </div>
        <!--
                <div class="layui-form-item">
                    <label  class="layui-form-label width105"><span style="color: red">*</span>存放仓库</label>
                    <div class="layui-input-inline ">
                        <select name="name"  lay-filter="aihao">
                            <option value="">请选择</option>
                            <option value="1">湖南富兰地工具有限公司</option>
                            <option value="2">湖南三一智能科技有限公司</option>
                            <option value="3">湖南云端商业管理有限公司</option>
                        </select>
                    </div>
                    <div class="layui-input-inline ">
                        <select name="name"  lay-filter="aihao">
                            <option value="">请选择</option>
                            <option value="1">一号仓</option>
                            <option value="2">二号仓</option>
                            <option value="3">三号仓</option>
                        </select>
                    </div>
                    <div class="layui-form-mid layui-word-aux">选择渠道公司，然后选择该公司所属的仓储</div>
                </div>

                <div class="layui-form-item">
                    <label  class="layui-form-label width105"><span style="color: red">*</span>所属刀柜分类</label>
                    <div class="layui-input-inline ">
                        <select name="name"  lay-filter="aihao">
                            <option value="">请选择</option>
                            <option value="1">顶级分类1</option>
                            <option value="2">顶级分类2</option>
                            <option value="3">顶级分类3</option>
                        </select>
                    </div>
                    <div class="layui-form-mid layui-word-aux">如果是刀柜顶级分类则不用填写</div>
                </div> -->

        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>柜子类型</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="dgxq_typeName"></span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>柜子型号</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="cabinetTypeId"></span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>所属品牌</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="brandName"></span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>柜子名称</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="dgxq_dgName"></span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>柜子编号</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="dgxq_code"></span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>取刀道总数</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red"></span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>取刀单柜货位数</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red"></span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>收刀货位总数</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red"></span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>收刀单柜货位数</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red"></span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>主板类型</label>
            <div class="layui-input-inline ">
                <!-- <select name="name"  lay-filter="aihao">
                    <option value="">请选择</option>
                    <option value="1">1西门子</option>
                    <option value="2">2云端</option>
                    <option value="3">3沃尔浮</option>
                </select> -->

                <div class="layui-form-mid layui-word-aux"><span id="dgxq_motherboardName"></span></div>

            </div>
            <div class="layui-form-mid layui-word-aux"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>升降主板类型</label>
            <div class="layui-input-inline ">
                <div class="layui-form-mid layui-word-aux"><span id="dgxq_hostTypeName"></span></div>
                <!-- <select name="name"  lay-filter="aihao">
                    <option value="">请选择</option>
                    <option value="1">1类型A</option>
                    <option value="2">2类型B</option>
                    <option value="3">3类型C</option>
                </select> -->
            </div>
            <div class="layui-form-mid layui-word-aux"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>描述</label>
            <div class="layui-input-inline ">
                <input type="text" class="layui-input" placeholder="这里是分类描述" name="" disabled>
            </div>
            <!-- <div class="layui-form-mid layui-word-aux"><span style="color: red">*</span></div> -->
        </div>
        <!-- <div class="layui-form-item">
            <label  class="layui-form-label width105"><span style="color: red">*</span>是否启用</label>
            <div class="layui-input-inline ">
                <input type="checkbox" checked=""  lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">
            </div> 
            <div class="layui-form-mid layui-word-aux"></div>
        </div> -->
        <!-- <div class="layui-form-item">
            <label  class="layui-form-label width105"><span style="color: red">*</span>排序</label>
            <div class="layui-input-inline ">
                <input type="text" class="layui-input" placeholder="" name="username" autocomplete="off">
            </div> 
            <div class="layui-form-mid layui-word-aux">数字，数字越小，排序越靠前</div>
        </div> -->
        <!-- <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="adddevicePopupFormSubmit" lay-submit type="button">保存</button>
        </div> -->
    </form>
</script>

<!-- 货位 -->
<script type="text/html" id="cargoLanelForm">
    <div class="layui-card layui-card-body">
        <form lay-filter="cargoLanelForm" class="layui-form model-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <input type="text" class="layui-input" placeholder="查看货位编号" name="laneCode" autocomplete="off">
                </div>
                <div class="layui-inline">
                    <button class="layui-btn icon-btn" lay-filter="cargoLanelSearchBtn" type="button" lay-submit="">
                        <i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>
        </form>
        <table class="layui-table" id="cargoLanelTable" lay-filter="cargoLanelTable"></table>
    </div>
</script>

<!--货位操作  cargoLanelFormBar  -->
<script type="text/html" id="cargoLanelFormBar">
    <a class="layui-btn  layui-btn-xs" lay-event="cargoLanelFormBarModify">修改参数</a>
</script>

<!--货位  参数修改-->
<script type="text/html" id="cargoLanelModifyForm">
    <div class="layui-card">
        <div class="layui-card-body cargoLanelModifyForm">
            <form lay-filter="cargoLanelModifyForm" class="layui-form model-form">
                <input name="id" type="hidden"/>
                <div class="layui-form-item">
                    <label class="layui-form-label">称重柜编码</label>
                    <div class="layui-input-inline">
                        <input name="cabCode" type="text" class="layui-input borderNone" disabled/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">货位编号</label>
                    <div class="layui-input-inline">
                        <input name="code" type="text" class="layui-input borderNone" disabled/>
                    </div>
                </div>
                <!--
                <div class="layui-form-item">
                    <label class="layui-form-label">货位状态</label>
                    <div class="layui-input-inline">
                        <input name="statusDesc" type="text" class="layui-input borderNone" disabled/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">货位库存状态</label>
                    <div class="layui-input-inline">
                        <input name="stockStatusDesc" type="text" class="layui-input borderNone" disabled/>
                    </div>
                </div>
                -->
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red">*</span>最大承重(克)</label>
                    <div class="layui-input-inline" style="width: calc(100% - 200px)">
                        <input name="maxBearing" type="number" class="layui-input" id="quantity"/>
                    </div>
                </div>
                <!--<div class="layui-form-item">
                    <label class="layui-form-label">货位库存状态</label>
                    <div class="layui-input-inline" style="width: calc(100% - 200px)">
                         <select name="storeType"  lay-filter="storeType">
                            <option value="common">公共存储</option>
                            <option value="person">专人存储</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item" id="cargoLanelModifyPrincipalBox" style="display: none">
                    <label class="layui-form-label">专人</label>
                    <div class="layui-input-inline" style="width: calc(100% - 200px)">
                        <div id="cargoLanelModifyPrincipal"></div>
                        <input type="hidden" name="storePerson">
                        <input type="hidden" name="storeName">
                    </div>
                </div>-->

                <div class="layui-form-item">
                    <label class="layui-form-label">存放备注提示</label>
                    <div class="layui-input-inline" style="width: calc(100% - 200px)">
                        <input name="remark" type="text" class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-inline">
                        <button class="layui-btn" type="button" id="cargoLanelModifyFormSubmit"
                                lay-filter="cargoLanelModifyFormSubmit" lay-submit>提交
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</script>


<!-- 暂存柜 -->
<!-- temporaryStorageCabinet -->
<script type="text/html" id="temporaryStorageCabinetForm">
    <!-- 头部操作 -->
    <div class="layui-card layui-card-body">
        <form lay-filter="temporaryStorageCabinetForm" class="layui-form model-form" style="padding-top: 0px">
            <!--            <div class="layui-form-item">-->
            <!--                <div class="layui-inline">-->
            <!--                    <button class="layui-btn icon-btn" lay-filter="temporaryStorageCabinetSetBtn" id="temporaryStorageCabinetSetBtn" type="button">-->
            <!--                        <i class="layui-icon">&#xe624;</i>货位参数设置-->
            <!--                    </button>-->
            <!--                </div>-->
            <!--            </div>-->
            <table class="layui-table" id="temporaryStorageCabinetFormTable"
                   lay-filter="temporaryStorageCabinetFormTable"></table>
        </form>

    </div>
</script>

<script type="text/html" id="temporaryStorageCabinetDetailForm">
    <!-- 头部操作 -->
    <div class="layui-card layui-card-body">
        <form lay-filter="temporaryStorageCabinetDetailForm" class="layui-form model-form" style="padding-top: 0px">
            <!--            <div class="layui-form-item">-->
            <!--                <div class="layui-inline">-->
            <!--                    <button class="layui-btn icon-btn" lay-filter="temporaryStorageCabinetSetBtn" id="temporaryStorageCabinetSetBtn" type="button">-->
            <!--                        <i class="layui-icon">&#xe624;</i>货位参数设置-->
            <!--                    </button>-->
            <!--                </div>-->
            <!--            </div>-->
            <table class="layui-table" id="temporaryStorageCabinetDetailFormTable"
                   lay-filter="temporaryStorageCabinetDetailFormTable"></table>
        </form>

    </div>
</script>

<!-- 供货位参数设置 -->
<!-- supplyParameters -->
<script type="text/html" id="supplyParametersForm">
    <!-- 头部操作 -->
    <div class="layui-card layui-card-body">
        <form lay-filter="supplyParametersForm" class="layui-form model-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <input type="text" class="layui-input" placeholder="查看货位编号" name="username" autocomplete="off">
                </div>
                <div class="layui-inline">
                    <button class="layui-btn icon-btn" lay-filter="" type="button">
                        <i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>

        </form>
        <table class="layui-table" id="supplyParametersFormTableOne" lay-filter="supplyParametersFormTableOne"></table>
        <table class="layui-table" id="supplyParametersFormTableTwo" lay-filter="supplyParametersFormTableTwo"></table>
    </div>
</script>

<!-- 供货位参数设置--》操作 -->
<script type="text/html" id="supplyParametersTableBar">
    <a class="layui-btn layui-btn-xs" lay-event="supplyParametersModify">修改</a>
</script>

<script type="text/html" id="supplyParametersTableBar2">
    <a class="layui-btn layui-btn-xs" lay-event="supplyParametersModify">修改</a>
    <a class="layui-btn layui-btn-xs" lay-event="detail">库存明细</a>
</script>

<!-- 供货位参数设置--》修改 -->
<!--supplyParametersModifyForm-->
<script type="text/html" id="supplyParametersModifyForm">
    <form lay-filter="supplyParametersModifyForm" class="layui-form model-form">
        <div class="layui-form-item">
            <label class="layui-form-label">货位状态</label>
            <div class="layui-input-block ">
                <select name="businessStatus" lay-verify="required">
                    <option value="">请选择</option>
                    <option value="normal">正常</option>
                    <option value="abnormal">异常</option>
                </select>
            </div>
        </div>
        <!--
        <div class="layui-form-item">
            <label class="layui-form-label">货位性质</label>
            <div class="layui-input-inline ">
                <select name="spaceNature" lay-verify="required" lay-filter="supplyParametersModifySpaceNature">
                    <option value="">请选择</option>
                    <option value="personal">专人存储</option>
                    <option value="common">公共存储</option>
                    <option value="specialClass">专类存储</option>
                    <option value="sku">按物料</option>
                    <option value="repair">盘验前报修存储</option>
                    <option value="recycle">盘验前报废存储</option>
                    <option value="repairChecked">盘验后报修存储</option>
                    <option value="recycleChecked">盘验后报废存储</option>
                </select>
            </div>
        </div>
        -->
        <div class="layui-form-item">
            <label class="layui-form-label">货位性质</label>
            <div class="layui-input-block ">
                <select name="spaceType" lay-verify="" lay-filter="supplyParametersModifySpaceNature">
                    <option value="common">通用</option>
                    <option value="temp">暂存</option>
                    <option value="repair">报修</option>
                    <option value="recycle">报废</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item" id="spaceProductTypeBox" style="display: block">
            <label class="layui-form-label">物料类型</label>
            <div class="layui-input-block ">
                <select name="spaceProductType" lay-verify="" lay-filter="spaceProductType"
                        id="spaceProductType"></select>
            </div>
        </div>
        <div class="layui-form-item" id="skuCodeBox" style="display: block">
            <label class="layui-form-label">物料编号</label>
            <div class="layui-input-block">
                <select name="skuCode" id="skuCode" lay-filter="skuCode" lay-verify="" lay-search required></select>
            </div>
        </div>
        <div class="layui-form-item" id="principalBox" style="display: block">
            <label class="layui-form-label">专人</label>
            <div class="layui-input-block ">
                <div id="principal"></div>
<!--                <select name="principal" lay-verify="" lay-filter="principal" id="principal"></select>-->
                <input type="hidden" name="principal">
                <input type="hidden" name="principalName">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">货位容量</label>
            <div class="layui-input-inline ">
                <input type="text" class="layui-input" name="quantity">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline ">
                <input type="text" class="layui-input" name="remark">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-inline ">
                <button class="layui-btn" lay-filter="supplyParametersModifyFormbtn" lay-submit="" type="button">保存
                </button>
            </div>
        </div>
    </form>
</script>


<!-- 物料 -->
<!-- product -->
<script type="text/html" id="productForm">
    <!-- 头部操作 -->
    <div class="layui-card layui-card-body">
        <form lay-filter="productForm" class="layui-form model-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <input type="text" class="layui-input" placeholder="查看货位编号" name="username" autocomplete="off">
                </div>
                <div class="layui-inline">
                    <button class="layui-btn icon-btn" lay-filter="productSearchBtn" type="button">
                        <i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>
        </form>
        <table class="layui-table" id="productTable" lay-filter="productTable"></table>
    </div>
</script>

<!-- 物料操作 -->
<script type="text/html" id="productTableBar">

    <a class="layui-btn layui-btn-xs" lay-event="distributionCargoWayBtn">分布货位</a>

    {{# if(d.cabinetNature =='main'){  }}
    <a class="layui-btn layui-btn-xs" lay-event="alarmSettingBtn">告警设置</a>
    <!--
    <a class="layui-btn layui-btn-xs" lay-event="loadingShelvesBtn">上货</a>
    -->
    {{# } }}


</script>

<!-- 物料（分布货位） -->
<!-- DistributionCargoWay -->
<script type="text/html" id="distributionCargoWay">
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-table" id="distributionCargoWayTable" lay-filter="distributionCargoWayTable"></table>
        </div>
    </div>
</script>

<!-- 物料（告警设置） -->
<!-- alarmSetting -->
<script type="text/html" id="alarmSetting">
    <form class="layui-form model-form" lay-filter="alarmSettingForm" action="">
        <input type="hidden" name="id">
        <!--
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>选择企业</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red">湖南云端商业管理有限公司</span>根据柜子自动带出企业</div>
        </div>
        -->
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>柜子编号</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="gjsz_cabCode"></span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red"></span>所在位置</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="gjsz_location">二号厂房/一车间/东边</span>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red"></span>物料</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="gjsz_productName">物料</span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red"></span>规格号</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="gjsz_specCode">规格号</span></div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label width105">告警库存数量</label>
            <div class="layui-input-inline ">
                <input type="text" class="layui-input" placeholder="告警库存数量" name="alarmStock" id="gjsz_alarmStock"
                       autocomplete="off">
            </div>
        </div>
        <!--
        <div class="layui-form-item">
            <label class="layui-form-label width105">最低补货目标</label>
            <div class="layui-input-inline ">
                <input type="text" class="layui-input" placeholder="最低补货目标" name="planReplenishment"
                       id="gjsz_planReplenishment" autocomplete="off">
            </div>

        </div>

        <div class="layui-form-item">
            <label class="layui-form-label width105">归还时长阈值</label>
            <div class="layui-input-inline ">
                <input type="text" class="layui-input" placeholder="最低补货目标" name="thresholdBlack"
                       id="thresholdBlack" autocomplete="off">
                <input name="thresholdBlack" placeholder="单位为小时(h)" min="0" type="number" class="layui-input"/>
            </div>

        </div>

        <div class="layui-form-item">
            <label class="layui-form-label width105">询问线</label>
            <div class="layui-input-inline ">
                <input type="text" class="layui-input" placeholder="询问线" name="proposalStock" id="gjsz_proposalStock"
                       autocomplete="off">
            </div>
        </div>
        -->
        <div class="layui-form-item">
            <label class="layui-form-label width105">备注</label>
            <div class="layui-input-inline ">
                <input type="text" class="layui-input" placeholder="备注" name="remarks" autocomplete="off"
                       id="gjsz_remarks">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105">设置时间</label>
            <div class="layui-form-mid layui-word-aux" id="gjsz_setTime"></div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label width105"></label>
            <button class="layui-btn" lay-filter="alarmSettingSubBtn" lay-submit type="button">提交保存</button>
        </div>
    </form>
</script>

<!-- 物料（上货） -->
<!-- loadingShelves -->
<script type="text/html" id="loadingShelves">
    <form lay-filter="loadingShelvesForm" class="layui-form model-form">
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>选择企业</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red">选择企业</span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>柜子编号</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="sh_number">柜子编号</span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red"></span>所在位置</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="sh_location">所在位置</span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red"></span>选择物料</label>
            <div class="layui-input-inline ">
                <input type="text" class="layui-input" placeholder="选择物料" name="productName" autocomplete="off">
                <!-- <select name="chanpin"  lay-filter="aihao">
                    <option value="">请选择</option>
                    <option value="1">物料A</option>
                    <option value="2">物料B</option>
                    <option value="3">物料C</option>
                </select> -->
            </div>
            <div class="layui-form-mid layui-word-aux"><span style="color: red"></span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105">选择货位</label>
            <div class="layui-input-inline ">
                <select name="loadingShelvesSpaceCode" lay-filter="loadingShelvesSpaceCode">
                    <!-- <option value="">请选择</option>
                    <option value="1">YD001-001</option>
                    <option value="2">YD001-002</option>
                    <option value="3">柜子编号+货位编码</option> -->
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105">备注</label>
            <div class="layui-input-inline ">
                <input type="text" class="layui-input" placeholder="备注" name="remarks" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105">上货配货员</label>
            <div class="layui-form-mid layui-word-aux" id="sh_distributionClerk">上货配货员</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105">开门时间</label>
            <div class="layui-form-mid layui-word-aux" id="sh_openingTime"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105">上货完成时间</label>
            <div class="layui-form-mid layui-word-aux" id="sh_completionTime">2021-05-06 12:00:00</div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label width105"></label>
            <button class="layui-btn" lay-filter="loadingShelvesSubBtn" lay-submit type="button">提交保存</button>
        </div>
    </form>
</script>

<!-- 订单 -->
<!-- order -->
<script type="text/html" id="orderForm">
    <div class="layui-card layui-card-body">
        <form lay-filter="orderForm" class="layui-form model-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <input type="text" class="layui-input" placeholder="查看货位编号" name="username" autocomplete="off">
                </div>
                <div class="layui-inline">
                    <button class="layui-btn icon-btn" lay-filter="orderSearchBtn" type="button"
                            lay-submit='orderSearchBtn'>
                        <i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>
        </form>
        <table class="layui-table" id="orderTable" lay-filter="orderTable"></table>
    </div>
</script>

<!--订单操作  -->
<script type="text/html" id="orderTableBar">
    <a class="layui-btn layui-btn-xs" lay-event="orderDetailsBtn">详情</a>
</script>

<!-- 订单详情 -->
<script type="text/html" id="orderDetails">
    <form lay-filter="orderDetailsForm" class="layui-form model-form">
        <!--<div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>选择企业</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="ddxq_companyName"></span></div>
        </div>-->
        <div class="layui-form-item">
            <label class="layui-form-label width105">订单编号</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="ddxq_code"></span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105">柜子编号</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="ddxq_cabCode"></span></div>
        </div>
        <!-- <div class="layui-form-item">
             <label class="layui-form-label width105">所在位置</label>
             <div class="layui-form-mid layui-word-aux"></div>
         </div>-->

        <div class="layui-form-item">
            <label class="layui-form-label width105">选择物料</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="ddxq_productName"></span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105">物料图片</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="ddxq_skuPic"></span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105">物料编号</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="ddxq_skuCode"></span></div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label width105">规格码</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="ddxq_skuSpec"></span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105">旧规格码</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="ddxq_skuSpecOld"></span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105">货位</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="ddxq_spaceCode"></span></div>
        </div>

        <!--  <div class="layui-form-item">
              <label class="layui-form-label width105"></span>成交单价</label>
              <div class="layui-form-mid layui-word-aux"><span style="color: red"></span></div>
          </div>-->
        <div class="layui-form-item">
            <label class="layui-form-label width105"></span>市场价</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="ddxq_marketPrice"></span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"></span>数量</label>
            <div class="layui-form-mid layui-word-aux"><span style="color: red" id="ddxq_quantity"></span></div>
        </div>
        <!-- <div class="layui-form-item">
             <label class="layui-form-label width105"></span>总价</label>
             <div class="layui-form-mid layui-word-aux"><span style="color: red"></span></div>
         </div>-->
        <!--  <div class="layui-form-item">
              <label class="layui-form-label width105">总优惠价</label>
              <div class="layui-form-mid layui-word-aux"><span style="color: red"></span></div>
          </div>-->
        <!--<div class="layui-form-item">
            <label class="layui-form-label width105">备注</label>
            <div class="layui-form-mid layui-word-aux">数字，数字越小，排序越靠前</div>
        </div>-->
        <div class="layui-form-item">
            <label class="layui-form-label width105">领取操作员</label>
            <div class="layui-form-mid layui-word-aux" id="ddxq_modifier"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105">领取人</label>
            <div class="layui-form-mid layui-word-aux" id="ddxq_creatorName"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105">订单提交时间</label>
            <div class="layui-form-mid layui-word-aux" id="ddxq_createTime"></div>
        </div>
        <!-- <div class="layui-form-item">
             <label class="layui-form-label width105">出货时间</label>
             <div class="layui-form-mid layui-word-aux">2021-05-06 12:00:00</div>
         </div>-->
        <!--<div class="layui-form-item">
            <label class="layui-form-label width105">订单状态</label>
            <div class="layui-form-mid layui-word-aux" id="ddxq_status">成交</div>
        </div>-->
        <!--  <div class="layui-form-item">
              <label class="layui-form-label width105">结算状态</label>
              <div class="layui-form-mid layui-word-aux">已结算</div>
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label width105">结算时间</label>
              <div class="layui-form-mid layui-word-aux">2021-05-06 12:00:00</div>
          </div>-->
        <!-- <div class="layui-form-item">
             <label class="layui-form-label width105">所属账单</label>
             <div class="layui-form-mid layui-word-aux">ZD201212001210</div>
         </div>-->
        <!--<div class="layui-form-item">
            <label class="layui-form-label width105">账单类型</label>
            <div class="layui-form-mid layui-word-aux">
                临时结算账单（临时结算账单为临时人工组建的账单，系统自动创建的账单记录为“系统结算账单”，系统结算账单总金额必须剔除账期内临时结算的账单）
            </div>
        </div>-->
        <!--<div class="layui-form-item">
            <label class="layui-form-label width105">支付方式</label>
            <div class="layui-form-mid layui-word-aux">银行汇款</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105">是否开票</label>
            <div class="layui-form-mid layui-word-aux">已开票</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105">发票编号</label>
            <div class="layui-form-mid layui-word-aux">FPZD201212001210</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105">发票附件</label>
            <div class="layui-form-mid layui-word-aux">FPZD201212001210.jpg(点击查看附件)</div>
        </div>-->
        <!-- <div class="layui-form-item">
            <label  class="layui-form-label width105"></label>
            <button class="layui-btn" lay-filter="" lay-submit type="button">提交保存</button>
        </div> -->
    </form>
</script>

<!--主柜权限-->
<script type="text/html" id="mainCabinetAuthorityForm">
    <form lay-filter="mainCabinetAuthorityForm" class="layui-form model-form  mainCabinetAuthorityForm">
        <div class="layui-row">
            <div class="layui-inline">
                <label class="layui-form-label">输入权限组名称：</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" placeholder="请输入权限组名称" name="name" autocomplete="off">
                </div>
            </div>
            <div class="layui-inline" style="padding-left: 10px;">
                <button class="layui-btn icon-btn color-green" type="button" lay-filter="mainCabinetAuthorityFormSearch"
                        lay-submit>
                    <i class="layui-icon layui-icon-search"></i>查询
                </button>
                <button class="layui-btn" type="button" id="addPermissionsGroupBtn">
                    <i class="layui-icon layui-icon-addition"></i>添加
                </button>
                <button class="layui-btn" type="button" id="permissionsExport">导出数据</button>
                <!--                <button class="layui-btn layui-btn-danger" type="button" lay-filter="">批量删除</button>-->
            </div>
        </div>
        <div class="open-details-box">
            <table class="layui-table" id="mainCabinetAuthorityTable" lay-filter="mainCabinetAuthorityTable"></table>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>
</script>

<!--权限弹窗操作列-->
<!--mainCabinetAuthorityFormTableBar-->
<script type="text/html" id="mainCabinetAuthorityFormTableBar">
    <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="details">详情</a>
    <a class="layui-btn layui-btn-xs" lay-event="modify">修改</a>
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="member">成员管理</a>
    {{# if(d.status =='0'){ }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="disable">禁用</a>
    {{# }else{ }}
    <a class="layui-btn layui-btn-xs" lay-event="enable">启用</a>
    {{# } }}

    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
</script>

<!--（添加、修改、详情）权限组-->
<!--addPermissionsGroup-->
<script type="text/html" id="addPermissionsGroupForm">
    <form lay-filter="addPermissionsGroupForm" class="layui-form model-form"
          style="padding: 5px 10px 0;height: calc(100% - 5px);overflow: hidden;">
        <div class="open-details-box"
             style="height: calc(100% - 65px); overflow-y: scroll; overflow-x: hidden; padding-top: 15px;">
            <input name="id" type="hidden" class="layui-input"/>
            <div class="layui-row layui-col-space20">
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">权限组名称</label>
                    <div class="layui-input-inline">
                        <input name="name" type="text" class="layui-input" placeholder="权限组名称"
                               lay-reqText="请输入权限组名称" lay-verify="required" autocomplete="off"/>
                    </div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">是否启用</label>
                    <div class="layui-input-block">
                        <input type="checkbox" checked="" name="status" lay-skin="switch" lay-filter="switchTest"
                               lay-text="启用|不启用">
                    </div>
                </div>

                <!--<div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">领新授信类型</label>
                    <div class="layui-input-inline">
                        <input type="radio" name="creditType" value="money" title="金额" checked=""
                               lay-filter="creditType">
                        <input type="radio" name="creditType" value="quantity" title="数量" lay-filter="creditType">
                    </div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">授信方式</label>
                    <div class="layui-input-inline">
                        <select name="creditWay" lay-verify="required" lay-reqText="请选择授信方式" lay-filter="creditWay">
                            <option value="">请选择授信方式</option>
                            <option value="share">组员共享领用金额</option>
                            <option value="independent">组员独立授信领用金额</option>
                            <option value="unlimited">不限制领用金额</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline layui-col-md6" id="moneyThresholdBox">
                    <label class="layui-form-label">未归还金额阈值</label>
                    <div class="layui-input-inline">
                        <input name="moneyThreshold" type="text" class="layui-input" placeholder="请输入金额"
                               lay-verify="required" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')"/>
                    </div>
                </div>
                <div class="layui-inline layui-col-md6" id="quantityThresholdBox" style="display: none">
                    <label class="layui-form-label">未归还数量阈值</label>
                    <div class="layui-input-inline">
                        <input name="quantityThreshold" type="text" class="layui-input" placeholder="请输入数量"
                               onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')"/>
                    </div>
                </div>
                <div class="layui-inline layui-col-md6" id="lineOfCreditBox">
                    <label class="layui-form-label">物料金额限制阈值</label>
                    <div class="layui-input-inline">
                        <input name="lineOfCredit" type="text" class="layui-input" placeholder="物料金额限制阈值"
                               id="lineOfCredit" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" lay-verify="required"/>
                    </div>
                </div>
                <div class="layui-inline layui-col-md6" style="display: none;" id="authorizedQuantityBox">
                    <label class="layui-form-label">物料数量限制阈值</label>
                    <div class="layui-input-inline">
                        <input name="authorizedQuantity" type="text" class="layui-input" placeholder="请输入物料数量限制阈值"
                               id="authorizedQuantity" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" />
                    </div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">额度评估周期</label>
                    <div class="layui-input-inline">
                        <select name="lineEvaluatePeriod" lay-verify="required" lay-reqText="请选择额度评估周期">
                            <option value="">请选择额度评估周期</option>
                            <option value="day">每天</option>
                            <option value="week">每周</option>
                            <option value="month">每月</option>
                            <option value="quarter">每季度</option>
                            <option value="year">每年</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline layui-col-md6" id="astrictMaterialBox">
                    <label class="layui-form-label">是否限制物料</label>
                    <div class="layui-input-inline">
                        <select name="astrictMaterial" lay-verify="required" lay-reqText="请选择是否限制物料"
                                lay-filter="astrictMaterial">
                            <option value="astrict">限制</option>
                            <option value="noAstrict">不限制</option>
                        </select>
                    </div>

                </div>-->

                <div class="layui-inline layui-col-md6" id="restrictWayBox">
                    <label class="layui-form-label">限制方式</label>
                    <div class="layui-input-inline">
                        <input type="radio" name="restrictWay" value="category" title="按分类限制" checked=""
                               lay-filter="materiel">
                        <input type="radio" name="restrictWay" value="materiel" title="按物料限制" lay-filter="materiel">
                    </div>
                </div>

                <div class="layui-inline layui-col-md6" id="materialIdBox">
                    <label class="layui-form-label">可领物资分类</label>
                    <input name="materialId" type="hidden" class="layui-input"/>
                    <div class="layui-input-inline" id="materialId" style="width: 280px;"></div>
                </div>

                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-inline">
                        <input name="remark" type="text" class="layui-input" placeholder="备注"/>
                    </div>
                </div>

            </div>
            <div class="layui-form-item" style="display: flex;align-items: center;justify-content: space-between;">
                <div class="color-title" style="flex: 1">SKU限制数</div>
                <button class="layui-btn color-green" type="button" id="addPermissionsGroupAdd" style="display: none">添加限制物料</button>
            </div>
            <div id="addPermissionsGroupFormTableBox">
                <table class="layui-table" id="addPermissionsGroupFormTable"
                       lay-filter="addPermissionsGroupFormTable"></table>
            </div>
        </div>

        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="addPermissionsGroupFormSubmit" lay-submit type="button">保存</button>
        </div>
    </form>
</script>

<!--权限组操作-->
<!--addPermissionsGroupFormTableBar-->
<script type="text/html" id="addPermissionsGroupFormTableBar">
    {{# if(d.colsIsShow){ }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
    {{# }else{ }}
    {{# } }}
</script>

<!--添加限制物料-->
<!--addRestrictedMaterials-->
<script type="text/html" id="addRestrictedMaterialsTemplate">
    <div lay-filter="addRestrictedMaterialsForm" class="layui-form model-form"
         style="padding: 15px 10px 0;height: calc(100% - 15px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 65px); overflow-y: auto;">
            <div class="layui-row">
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">物料名称</label>
                    <div class="layui-input-inline">
                        <input name="skuName" type="text" class="layui-input" placeholder="请输入物料名称" autocomplete="off"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">物料编号</label>
                    <div class="layui-input-inline">
                        <input name="skuCode" type="text" class="layui-input" placeholder="请输入物料编号" autocomplete="off"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">规格码</label>
                    <div class="layui-input-inline">
                        <input name="oldSpecCode" type="text" class="layui-input" placeholder="请输入规格码" autocomplete="off"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">品牌</label>
                    <div class="layui-input-inline">
                        <input name="productBrandName" type="text" class="layui-input" placeholder="请输入品牌" autocomplete="off"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn icon-btn color-green"
                            lay-filter="addRestrictedMaterialsFormSearch" lay-submit layui-form-keyDownSearch="true"><i
                            class="layui-icon layui-icon-search"></i>查询
                    </button>
                </div>
            </div>
            <div class="layui-form-item">
                <table class="layui-table" id="addRestrictedMaterialsFormTable"
                       lay-filter="addRestrictedMaterialsFormTable"></table>
            </div>
        </div>

        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="addRestrictedMaterialsFormSubmit" lay-submit id="addRestrictedMaterialsFormSubmit">保存</button>
        </div>
    </div>
</script>

<!--成员管理-->
<!--memberForm-->
<script type="text/html" id="memberForm">
    <div lay-filter="memberForm" class="layui-form model-form"
         style="padding: 20px 20px 0;height: calc(100% - 20px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 65px); overflow-y: auto;">
            <div class="layui-row">
                <label class="layui-form-label w-auto">成员姓名</label>
                <div class="layui-input-inline">
                    <input name="userName" type="text" class="layui-input" placeholder="输入成员姓名"/>
                </div>
                <div class="layui-inline" style="padding-left: 10px;">
                    <button type="button" class="layui-btn icon-btn color-green"
                            lay-filter="memberFormSearch" lay-submit ><i class="layui-icon layui-icon-search" layui-form-keyDownSearch="true"></i>查询
                    </button>
                    <button type="button" class="layui-btn icon-btn" id="addMembersBtn">添加成员</button>
                    <button type="button" class="layui-btn icon-btn" id="memberFormExport">导出数据</button>
                    <button type="button" class="layui-btn icon-btn layui-btn-danger" id="memberFormBatchDeletion">批量删除
                    </button>
                </div>
            </div>
            <div class="layui-form-item">
                <table class="layui-table" id="memberFormTable" lay-filter="memberFormTable"></table>
            </div>
        </div>

        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <!--            <button class="layui-btn" lay-filter="memberFormFormSubmit" lay-submit>保存</button>-->
        </div>
    </div>
</script>


<!--成员管理操作列-->
<!--memberFormBar-->
<script type="text/html" id="memberFormTableBar">
    <a class="layui-btn layui-btn-xs" lay-event="details">详情</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
</script>

<!--添加权限组成员-->
<!--addPermissionGroupMembers-->
<script type="text/html" id="addPermissionGroupMembers">
    <div lay-filter="addPermissionGroupMembersForm" class="layui-form model-form"
         style="padding: 5px 20px 0;height: calc(100% - 5px);overflow: hidden;" id="addPermissionGroupMembersForm">
        <div class="open-details-box"
             style="height: calc(100% - 65px); overflow-y: auto; overflow-x: hidden; padding-top: 15px;">
            <div class="layui-form-item">
                <label class="layui-form-label">权限组名称</label>
                <div class="layui-input-block">
                    <input name="name" type="text" class="layui-input" style="border-color: transparent" disabled/>
                </div>
            </div>
            <div class="layui-form-item" id="addPermissionGroupMembersFormLineOfCreditBox" style="display: none">
                <label class="layui-form-label">授权额度</label>
                <div class="layui-input-block">
                    <input name="lineOfCredit" type="text" class="layui-input" style="border-color: transparent"
                           disabled/>
                </div>
            </div>
            <div class="layui-form-item" id="addPermissionGroupMembersFormAuthorizedQuantityBox" style="display: none">
                <label class="layui-form-label">授权数量</label>
                <div class="layui-input-block">
                    <input name="authorizedQuantity" type="text" class="layui-input" style="border-color: transparent"
                           disabled/>
                </div>
            </div>


            <div class="layui-form-item" id="materialId1Box" style="display: none">
                <label class="layui-form-label">可领物资分类</label>
                <input name="materialId" type="hidden"/>
                <div class="layui-input-block" id="materialId1"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">选择人员</label>
                <div class="layui-input-block" id="userIdBox"></div>
                <div class="layui-input-block addPermissionGroupMembersDetail">
                    <input type="text" name="userName" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item addPermissionGroupMembersDetail">
                <label class="layui-form-label">选择企业</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="enterpriseName" disabled>
                </div>
            </div>
            <div class="layui-form-item addPermissionGroupMembersDetail">
                <label class="layui-form-label">选择部门</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="deptName" disabled>
                </div>
            </div>

            <div class="layui-form-item addPermissionGroupMembersDetail">
                <label class="layui-form-label">选择岗位</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="positionName" disabled>
                </div>
            </div>

            <div class="layui-form-item addPermissionGroupMembersDetail">
                <label class="layui-form-label">工号</label>
                <div class="layui-input-block">
                    <input name="jobNumber" type="text" class="layui-input" disabled/>
                </div>
            </div>
            <div class="layui-form-item addPermissionGroupMembersDetail">
                <label class="layui-form-label">手机号</label>
                <div class="layui-input-block">
                    <input name="phone" type="text" class="layui-input" disabled/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否启用</label>
                <div class="layui-input-block">
                    <input type="checkbox" checked="" name="isDeleted" lay-skin="switch" lay-filter="switchTest"
                           lay-text="启用|不启用">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <input name="remark" type="text" class="layui-input" placeholder="备注"/>
                </div>
            </div>
        </div>

        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="addPermissionGroupMembersFormSubmit" lay-submit>保存</button>
        </div>
    </div>
</script>





<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin','tableTreeDj'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var tableTree = layui.tableTreeDj;

        //  渲染接入称重柜表格
        var insTb = tableTree.render({
            id: '#toolCabinetTable',
            elem: '#toolCabinetTable',
            url: config.base + 'enterprisecab/wcabinet/admin/wcabinet/list?cabinetTypeId=&cabinetBrandId=&status=&code=&&cabinetNature=main',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers',title:'序号'}
                // , {field: 'id', title: '称重柜编号', sort: true}
                // , {field: 'typeName', title: '称重柜类型'}
                // , {field: 'brandName', title: '所属品牌'}
                 , {field: 'name', title: '柜子名称'}
                , {field: 'belongCabinet', title: '所属主柜'}
                , {field: 'cabCode', title: '系统编码'}
                , {field: 'cabName', title: '企业自定义名称',width: 130}
                , {field: 'code', title: '系统自定义编码',width: 130}
                , {field: 'settledCompanyName', title: '所属企业'}
                , {field: 'workshopLocation', title: '所在地'}
                , {field: 'cabCodes', title: '辅柜编码'}
                , {field: 'cabNum', title: '辅柜数'}
                // , {field: 'cabinetNatureDesc', title: '柜子性质'}
                // , {field: 'creatorName', title: '责任人'}
                // , {field: 'statusDesc', title: '状态'}
                // , {field: 'submitter', title: '添加人'}
                // , {field: 'createTime', title: '添加时间'}
                , {toolbar: '#toolCabinetTableBar', title: '操作', width: 450}
            ]],
            done: function (res, curr, count) {
            //    默认展开数据
            res.data.forEach(item => {
                tableTree.showByPid(item.id, '#toolCabinetTable')
            });
        }
        }, {keyPid: "parentId", title: "name"});
        form.render('select');
        toolCabinetTypeData();
        channelBrandData();

        function toolCabinetTypeData() {
            admin.req('enterprisecab/cabProduct/admin/productType/getProductTypeByType', {type: 1}, function (res) {
                $.each(res.data, function (index, value) {
                    // console.log(value.department_id);
                    $('#toolCabinetType').append(new Option(value.name, value.name));// 下拉菜单里添加元素
                });
                layui.form.render("select");//重新渲染 固定写法
            }, 'GET');
        }

        function channelBrandData() {
            admin.req('enterprisecab/cabProduct/admin/productBrand/getAllProductBrandByType', {type: 1}, function (res) {
                $.each(res.data, function (index, value) {
                    // console.log(value.department_id);
                    $('#channelBrand').append(new Option(value.name, value.name));// 下拉菜单里添加元素
                });
                layui.form.render("select");//重新渲染 固定写法
            }, 'GET');
        }

        // 工具条点击事件
        table.on('tool(toolCabinetTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'details') { //详情
                showAdddevicePopup(data);
            } else if (obj.event === 'cargoLaneBtn') {  // 货位
                showCargoLane(data);
            } else if (obj.event === 'temporaryStorageCabinetBtn') { // 暂存柜
                showTemporaryStorageCabinet(data)
            } else if (obj.event === 'productBtn') { // 物料
                showProductForm(data)
            } else if (obj.event === 'orderBtn') { // 订单
                showOrder(data)
            } else if (obj.event === 'delete') {
                delToolCabinet(data)
            } else if (obj.event === 'modifyBtn') {
                showModify(data);
            }else if (obj.event === 'permissionsBtn') {
                // showPermissions(data)
                mainCabinetAuthorityFun(data)
            }
        });

        function showModify(data) {
            admin.open({
                type: 1,
                area: '400px',
                offset: '65px',
                title: '修改企业信息',
                content: $('#companyForm').html(),
                success: function () {
                    form.val('companyForm', data);

                    if(data.cabinetNature!='main'){
                        // $("from input[name='settledCompanyId']").attr('disabled','disabled');
                        // $("from input[name='settledCompanyId']").attr('disabled','disabled');
                    }

                    //检查唯一性
                    /*form.verify({
                        isOnlyCode: function (value) {
                            var isOnly = true;
                            var idVal = $("form input[name='id']").val();
                            admin.req('enterprisecab/cabinet/admin/cabinet/isOnly', {code:value,id:idVal}, function (res) {
                                if (res.code == 200) {
                                    isOnly = res.data;
                                }
                            }, 'GET',false);
                            if(!isOnly){
                                return "编码必须唯一"
                            }
                        },
                        integer: [/^([0-9]\d*|[ \t]*)$/, '格式错误']
                    })*/

                    // 获取企业数据
                    admin.req('user/admin/companyInfo/list', {limit: 9999}, function (res) {
                        if (res.code == 200) {
                            var html = '<option value="">请选择企业</option>';
                            for (var k = 0; k < res.data.length; k++) {
                                html += '<option value="' + res.data[k].id + '">' + res.data[k].name + '</option>';
                            }
                            $("form select[name='settledCompanyId']").html(html);
                            form.render('select');
                            if (data && data.settledCompanyId) {
                                form.val('companyForm', data);
                            }

                        } else {
                            layer.msg('获取企业失败', {icon: 2, time: 1000});
                        }
                    }, 'GET');

                    // 表单提交事件
                    form.on('submit(companyFormSubmit)', function (d) {
                        layer.load(2);
                        d.field.cabCode=data.cabCode;
                        d.field.settledCompanyName=$("form select[name='settledCompanyId'] option:selected").text();
                        admin.req('enterprisecab/cabinet/admin/cabinet/updateCompany', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                insTb.reload('toolCabinetTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'PUT');
                        return false;
                    });
                }
            });
        }


        function delToolCabinet(_data) {
            layer.confirm('确定删除吗？', {
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprisecab/cabinet/admin/cabinet/' + _data.id, {}, function (data) {
                    layer.closeAll('loading');
                    if (data.code == 200) {
                        layer.msg(data.msg, {icon: 1});
                        table.reload('toolCabinetTable');
                        layer.closeAll('page');
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }

        //监听排序
        table.on('sort(toolCabinetTable)', function (obj) {
            table.reload('toolCabinetTable', {initSort: obj, where: {sort: obj.field, order: obj.type}});
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
            return false;
        });


        // 添加设备点击事件
        $("#productPackLabelBtnAdd").click(d => {
            showAdddevicePopup()
        });

        // 显示添加设备弹窗/详情
        function showAdddevicePopup(data) {
            admin.open({
                type: 1,
                area: ['800px', '800px'],
                offset: '65px',
                title: data ? '详情' : '添加设备',
                content: $('#adddevicePopup').html(),
                success: function (_data) {
                    form.render();

                    admin.req('enterprisecab/cabinet/admin/cabinet/queryDetail?cabCode=' + data.code, {}, function (res) {
                        layer.closeAll('loading');
                        if (res.code == 200) {
                            $('#dgxq_typeName').html(res.data.typeName);
                            $('#brandName').html(res.data.brandName);
                            $('#cabinetTypeId').html(res.data.cabinetTypeId);
                            $('#dgxq_dgName').html(res.data.name);
                            $('#dgxq_code').html(res.data.code + '-');
                            $('#dgxq_motherboardName').html(res.data.motherboardName);
                            $('#dgxq_hostTypeName').html(res.data.hostTypeName);
                        } else {
                            $('#dgxq_typeName').html(data.typeName);
                            $('#brandName').html(data.brandName);
                            $('#cabinetTypeId').html(data.cabinetTypeId);
                            $('#dgxq_dgName').html(data.name);
                            $('#dgxq_code').html(data.code + '-');
                            $('#dgxq_motherboardName').html(data.motherboardName);
                            $('#dgxq_hostTypeName').html(data.hostTypeName);
                        }
                    }, 'GET', false, 'application/json; charset=utf-8');
                }
            })
        }

        //显示货位弹窗
        function showCargoLane(data) {

            // let tableUrl = ;
            // if (data.cabinetNature == 'sale') {
            //     tableUrl = config.base + 'enterprisecab/cabinet/admin/cabinetCargoLane/list?cabCode=' + data.code
            // } else {
            //     tableUrl = config.base + 'enterprisecab/cabinet/admin/cabinetCargoSpace/list?cabCode=' + data.cabinetSku;
            // }
            admin.open({
                type: 1,
                area: ['1540px', '800px'],
                offset: '65px',
                title: '货位',
                content: $('#cargoLanelForm').html(),
                success: function () {
                    form.render();
                    var cabType = data.cabinetNature;
                    var queryFlag = undefined;
                    var url = config.base + 'enterprisecab/cabinet/admin/cabinetCargoLane/list?wsFlag=gravity&cabinetId=' + data.id + '&sort=id';
                    if (cabType == 'main') {
                        queryFlag = "mainCab";
                        url = config.base + 'enterprisecab/cabinet/admin/cabinetCargoLane/list?wsFlag=gravity&mainCabCode=' + data.cabCode + '&sort=id&queryFlag=' + queryFlag + '&cabinetNature=sale';
                    }
                    var cargoLanelTb = table.render({
                        elem: '#cargoLanelTable',
                        // url: config.base + 'enterprisecab/cabinet/admin/cabinetCargoSpace/list?cabCode=' + data.cabinetSku,
                        url: url,
                        // url: config.base + 'enterprisecab/cabinet/admin/cabinetCargoLane/list?cabCode=' + data.code,
                        // url: config.base + 'enterprisecab/cabinet/admin/cabinetCargoLane/list',
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'code', title: '货位编号', sort: true}
                            // {field: 'laneCode', title: '货位编号', sort: true}
                            , {field: 'cabCode', title: '柜子编号'}
                            , {field: 'skuName', title: '物料名称'}
                            ,  {field: 'skuCode', title: '物料编号'}
                            , {field: 'brandName', title: '品牌'}
                            , {field: 'weight', title: '库存重量'}
                            , {field: 'weightMax', title: '最大承重',templet:function (d) {
                                    return d.weightMax+'克';
                                }}
                            , {field: 'weightUnitDesc', title: '重量单位'}
                            // , {field: 'quantity', title: '库存数量'}
                            , {field: 'currentStockCount', title: '库存数量'}
                            , {field: 'unitName', title: '数量单位'}

                            // , {field: 'currentStockCount', title: '库存数量'}
                            // , {field: 'quantity', title: '货位容量'}
                            // , {field: 'remark', title: '备注'}
                            // , {field: 'statusDesc', title: '货位状态'}
                            // , {field: 'stockStatusDesc', title: '库存状态'}
                            // , {field: 'createTime', title: '截至时间'}
                            , {align: 'center', title: '操作', toolbar: "#cargoLanelFormBar"}

                        ]],
                    });

                    //搜索
                    form.on('submit(cargoLanelSearchBtn)', function (data) {
                        cargoLanelTb.reload({where: data.field, page: {curr: 1}}, 'data');
                        return false;
                    });

                    // 工具条点击事件
                    table.on('tool(cargoLanelTable)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'cargoLanelFormBarModify') { //详情
                            showCargoLanelModifyForm(data)
                        }
                    });

                }

            })
        }

        function showCargoLanelModifyForm(_data) {
            let cargoLanelModifyFormOpen = admin.open({
                type: 1,
                area: "800px",
                offset: '85px',
                title: '编辑货位参数',
                content: $('#cargoLanelModifyForm').html(),
                success: function () {
                    let cargoLanelModifyPrincipal;
                    if(JSON.stringify(_data.storeType) == '{}' || _data.storeType == ''){
                        _data.storeType = 'common';
                    }
                   /* admin.reqSync('user/admin/user/getAll', {}, res => {
                        if (res.code == '200') {
                            cargoLanelModifyPrincipal= xmSelect.render({
                                el: '#cargoLanelModifyPrincipal',
                                filterable: true,
                                autoRow: true,
                                height: '200px',
                                initValue: _data.storePerson.split(','),
                                model: {label: {type: 'text'}},
                                data() {
                                    let treeData = [];
                                    res.data.forEach(item => {
                                        treeData.push({
                                            name: item.nickname + "|" + item.username,
                                            value: item.id
                                        })
                                    });
                                    return treeData;
                                },
                                on: function (data) {
                                    let arr = data.arr, principalData = [], principalNameData = [];
                                    arr.forEach((item) => {
                                        principalData.push(item.value);
                                        principalNameData.push(item.name);
                                    });
                                    $('form[lay-filter="cargoLanelModifyForm"] input[name="storePerson"]').val(principalData.join());
                                    $('form[lay-filter="cargoLanelModifyForm"] input[name="storeName"]').val(principalNameData.join());
                                },
                            })
                        }
                    }, 'GET');*/
                    cargoLanelModifyPrincipalBoxShow(_data.storeType);

                    form.on("select(storeType)", function (data) {
                        cargoLanelModifyPrincipalBoxShow(data.value)
                    });

                    function cargoLanelModifyPrincipalBoxShow(_data){
                        /*if(_data == 'person'){
                            $('#cargoLanelModifyPrincipalBox').show(300);
                                cargoLanelModifyPrincipal.update({layVerify: 'required'})
                        }else {
                            $('#cargoLanelModifyPrincipalBox').hide(300);
                            cargoLanelModifyPrincipal.update({layVerify: false})
                        }*/
                    }

                    form.val('cargoLanelModifyForm', _data);
                    // $("#quantity").blur(() => {
                    //     if ($("#quantity").val() > _data.quantity) {
                    //         $("#quantity").val(_data.quantity);
                    //         layer.msg("不能超过最大值", {icon: 5})
                    //     }
                    // })

                    //提交
                    form.on('submit(cargoLanelModifyFormSubmit)', (d) => {
                        if(d.field.storeType == 'common'){
                            d.field.storePerson = void 1;
                            d.field.storeName = void 1;
                        }
                        layer.load(2);
                        let scatterFromSubmitData = Object.assign(_data, d.field);
                        admin.req('enterprisecab/cabinet/admin/cabinetCargoLane/update', scatterFromSubmitData, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('cargoLanelTable');
                                layer.close(cargoLanelModifyFormOpen);
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'PUT');
                        return false;
                    })

                }
            })
        }


        //暂存柜弹窗
        function showTemporaryStorageCabinet(data) {
            admin.open({
                type: 1,
                area: '1740px',
                offset: '65px',
                title: '称重柜货位列表',
                content: $('#temporaryStorageCabinetForm').html(),
                success: function () {
                    var cabType = data.cabinetNature;
                    var queryFlag = undefined;
                    var url = config.base + 'enterprisecab/cabinet/admin/cabinetCargoSpace/list4pc?cabinetId=' + data.id + '&sort=id';
                    if (cabType == 'main') {
                        queryFlag = 'mainCab'
                        url = config.base + 'enterprisecab/cabinet/admin/cabinetCargoSpace/list4pc?mainCabCode=' + data.cabCode + '&sort=id' + '&queryFlag=' + queryFlag + '&cabinetNature=live';
                    }
                    var cargoLanelTb = table.render({
                        elem: '#temporaryStorageCabinetFormTable',
                        //url: config.base + 'enterprisecab/cabinet/admin/storageInventorySpace/list?cabCode='+data.cabinetSku, //
                        // url: config.base + 'enterprisecab/cabinet/admin/cabinetCargoSpace/list?cabCode=' + data.cabinetSku,
                        url: url,
                        page: true,
                        cellMinWidth: 110,
                        cols: [[
                            {field: 'spaceCode', title: '货位', sort: true}
                            // , {field: 'cabinetId', title: '所属柜子'}
                            , {field: 'cabCode', title: '所属柜子'}
                            // , {field: 'productId', title: '存放物料'}
                            // , {field: 'productSku', title: '物料编号'}
                            // , {field: 'skuName', title: '物料名称'}
                            , {field: 'productTypeName', title: '已存物料类型'}
                            , {field: 'skuCode', title: '已存物料编号'}
                            , {field: 'brandName', title: '品牌'}
                            , {field: 'quantityInventory', title: '库存数量'}
                            , {field: 'quantity', title: '货位容量'}
                            , {field: 'businessStatusDesc', title: '货位状态'}
                            , {field: 'spaceTypeDesc', title: '货位性质'}
                            , {field: 'spaceProductTypeName', title: '物料类型'}
                            , {field: 'skuCodeTarget', title: '物料编号'}
                            , {field: 'principalName', title: '专人'}
                            // , {field: 'remark', title: '备注'}
                            , {
                                field: 'businessTypeDesc', title: '业务状态'
                            }
                            , {field: 'remark', title: '备注'}
                            // , {field: 'createTime', title: '截至时间'}
                            , {toolbar: '#supplyParametersTableBar2',width:200, title: '操作'}
                        ]],
                    });

                    table.on('tool(temporaryStorageCabinetFormTable)', function (obj) {
                        var dataSpace = obj.data;
                        if (obj.event === 'supplyParametersModify') {
                            showSupplyParametersModifyForm(dataSpace)
                        }else if(obj.event =='detail'){
                            dataSpace.cabType=data.cabType;
                            dataSpace.spaceCode=dataSpace.code;
                            dataSpace.cabinetId=data.id;
                            dataSpace.cabCode=data.cabCode;
                            showTemporaryStorageCabinetDetail(dataSpace);
                        }
                    });

                    $("#temporaryStorageCabinetSetBtn").click(d => {
                        showSupplyParameters(data)
                    })

                }
            });
        }

        function showTemporaryStorageCabinetDetail(data) {
            admin.open({
                type: 1,
                area: '1740px',
                offset: '65px',
                title: '库存列表',
                content: $('#temporaryStorageCabinetDetailForm').html(),
                success: function () {
                    var cabType = data.cabinetNature;
                    var queryFlag = undefined;
                    var url = config.base + 'enterprisecab/cabinet/admin/cabinetCargoSpace/list?cabinetId=' + data.cabinetId + '&sort=id'+'&spaceCode4Query='+data.spaceCode;
                    if (cabType == 'main') {
                        queryFlag = 'mainCab'
                        url = config.base + 'enterprisecab/cabinet/admin/cabinetCargoSpace/list?mainCabCode=' + data.cabCode + '&sort=id' + '&queryFlag=' + queryFlag + '&cabinetNature=live'+'&spaceCode='+data.spaceCode;
                    }
                    var cargoLanelTb = table.render({
                        elem: '#temporaryStorageCabinetDetailFormTable',
                        //url: config.base + 'enterprisecab/cabinet/admin/storageInventorySpace/list?cabCode='+data.cabinetSku, //
                        // url: config.base + 'enterprisecab/cabinet/admin/cabinetCargoSpace/list?cabCode=' + data.cabinetSku,
                        url: url,
                        page: true,
                        cellMinWidth: 110,
                        cols: [[
                            {field: 'spaceCode', title: '货位', sort: true}
                            // , {field: 'cabinetId', title: '所属柜子'}
                            , {field: 'cabCode', title: '所属柜子'}
                            // , {field: 'productId', title: '存放物料'}
                            // , {field: 'productSku', title: '物料编号'}
                            // , {field: 'skuName', title: '物料名称'}
                            , {field: 'productTypeName', title: '已存物料类型'}
                            , {field: 'skuCode', title: '已存物料编号'}
                            , {field: 'brandName', title: '品牌'}
                            , {field: 'quantityInventory', title: '库存数量'}
                            , {field: 'quantity', title: '货位容量'}
                            , {field: 'businessStatusDesc', title: '货位状态'}
                            , {field: 'spaceTypeDesc', title: '货位性质'}
                            , {field: 'spaceProductTypeName', title: '物料类型'}
                            , {field: 'skuCodeTarget', title: '物料编号'}
                            , {field: 'principalName', title: '专人'}
                            // , {field: 'remark', title: '备注'}
                            , {
                                field: 'businessTypeDesc', title: '业务状态'
                            }
                            , {field: 'remark', title: '备注'}
                            // , {field: 'createTime', title: '截至时间'}
                        ]],
                    });



                }
            });
        }

        // 暂存柜货位设置
        function showSupplyParameters(data) {
            admin.open({
                type: 1,
                area: '1200px',
                offset: '85px',
                title: '暂存柜货位性质设置',
                content: $('#supplyParametersForm').html(),
                success: function () {
                    var supplyParametersFormTableOne = table.render({
                        elem: '#supplyParametersFormTableOne',
                        // url: config.base + '',
                        data: [data],
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'id', title: '所属主柜'}
                            , {field: '', title: '所属副柜'}
                            , {field: '', title: '总货位数'}
                            , {field: '', title: '通用存刀位'}
                            , {field: '', title: '专属存刀位'}
                            , {field: 'companyName', title: '企业'}
                            , {field: 'workshopLocation', title: '所属车间'}
                            , {field: '', title: '车间描述'}
                            , {field: 'submitter', title: '管理员'}
                            , {field: 'createTime', title: '启用时间'}
                        ]],
                    })

                    var supplyParametersFormTableTwo = table.render({
                        elem: '#supplyParametersFormTableTwo',
                        url: config.base + 'enterprisecab/cabinet/admin/cabinetCargoLane/list?cabCode=' + data.cabCode,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'id', title: '货位ID'}
                            , {field: '', title: '货位状态'}
                            , {field: '', title: '	备注'}
                            , {field: '', title: '业务状态'}
                            , {field: '', title: '货位性质'}
                            , {field: '', title: '权责人'}
                            , {toolbar: '#supplyParametersTableBar', title: '操作'}
                        ]],

                    });
                    table.on('tool(supplyParametersFormTableTwo)', function (obj) {
                        let data = obj.data;
                        if (obj.event === 'supplyParametersModify') {
                            showSupplyParametersModifyForm(data)
                        }
                    })
                }
            })
        }

        // 暂存柜货位属性设置修改弹窗
        function showSupplyParametersModifyForm(data) {
            data.skuCode=data.skuCodeTarget;
            let supplyParametersModifyFormPopup = admin.open({
                type: 1,
                area: ['800px', '500px'],
                offset: '100px',
                title: '货位参数性质设置',
                content: $('#supplyParametersModifyForm').html(),
                success: function () {
                    //权责人
                    admin.reqSync('user/admin/user/getAll', {}, res => {
                        if (res.code == '200') {
                            // loadSelectHtml(res.data, '请选择权责人', 'principal', 5)
                            xmSelect.render({
                                el: '#principal',
                                filterable: true,
                                initValue: data.principal.split(','),
                                model: {label: {type: 'text'}},
                                data() {
                                    let treeData= [];
                                    res.data.forEach(item=>{
                                        treeData.push({ name: item.nickname + "|" + item.username, value: item.id})
                                    });
                                    return treeData;
                                },
                                on: function (data) {
                                    let arr = data.arr,principalData =[],principalNameData = [];
                                    arr.forEach((item)=>{
                                        principalData.push(item.value);
                                        principalNameData.push(item.name);
                                    });
                                    $('form[lay-filter="supplyParametersModifyForm"] input[name="principal"]').val(principalData.join());
                                    $('form[lay-filter="supplyParametersModifyForm"] input[name="principalName"]').val(principalNameData.join());
                                },
                            })
                        }
                    }, 'GET');

                    var getProduct=function(productTypeId){
                        admin.req('enterprise/product/admin/productDetail/list', {productTypeId:productTypeId,limit:999}, function (res) {

                            if (res.code == 200) {
                                var html='<option value="">请选择物料</option>'
                                for(var k=0;k<res.data.length;k++){
                                    html+='<option value="'+res.data[k].skuCode+'"data-skucode="'+res.data[k].skuCode+'">'+'物料编号:'+res.data[k].skuCode+'|物料名称:'+res.data[k].skuName+'|规格:'+res.data[k].oldSpecCode+'</option>'
                                }
                                $("#skuCode").html(html);
                                form.render('select');
                                if(data){
                                    $("#skuCode").val(data.skuCode);
                                    form.render('select');
                                    // getCabSpace(data.cabId,data.skuCode);
                                }
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                    }

                    //存储类目
                        admin.req('enterprise/product/admin/productType/getAllKnife', {limit:999}, function (res) {
                        if (res.code == '200') {
                            // loadSelectHtml(res.data, '请选择存储类目', 'spaceProductType', 6)
                            if (res.code == 200) {
                                var html='<option value="">请选择物料类型</option>'
                                for(var k=0;k<res.data.length;k++){
                                    html+='<option value="'+res.data[k].id+'">'+res.data[k].name+'</option>'
                                }
                                $("#spaceProductType").html(html);
                                form.render('select');
                                if(data){
                                    $("#spaceProductType").val(data.spaceProductType);
                                    form.render('select');
                                    getProduct(data.spaceProductType);
                                }
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    }, 'GET');



                    form.on('select(spaceProductType)',function(data){
                        if(data.value!=''){
                            getProduct(data.value);
                        }
                    })


                    /**
                    if (data.spaceNature) {
                        if (data.spaceNature == "personal") { //专人存储
                            $('#principalBox').show();
                            //$('#spaceProductType').val('');
                            $('#spaceProductType').removeAttr('lay-verify');
                            $('#skuCode').removeAttr('lay-verify');

                        } else if (data.spaceNature == "specialClass") { // 专类存储
                            $('#spaceProductTypeBox').show();
                            $('#principal').removeAttr('lay-verify');
                            $('#skuCode').removeAttr('lay-verify');
                        } else if(data.spaceNature == "sku"){
                            $('#skuCodeBox').show();
                            $('#spaceProductType').removeAttr('lay-verify');
                            $('#principal').removeAttr('lay-verify');

                        } else{
                            // 公共存储   报修存储   回收报废存储
                            $('#spaceProductTypeBox').hide();
                            $('#spaceProductType').val('');
                            $('#spaceProductType').removeAttr('lay-verify');
                            $('#principalBox').hide();
                            $('#principal').val('');
                            $('#principal').removeAttr('lay-verify');

                            $('#skuCodeBox').hide();
                            $('#skuCodeBox').val('');
                            $('#skuCodeBox').removeAttr('lay-verify');
                        }
                    }*/


                    form.val("supplyParametersModifyForm", data);
                    form.render();


                    // /cabinet/admin/cabinetCargoLane/update
                    /**
                    form.on('select(supplyParametersModifySpaceNature)', d => {
                        //spaceProductTypeBox存储类目  principalBox 权责人

                        if (d.value == "personal") { //专人存储
                            $('#principalBox').show();
                            $('#principal').attr('lay-verify', "required");

                            $('#spaceProductTypeBox').hide();
                            $('#spaceProductType').val('');
                            $('#spaceProductType').removeAttr('lay-verify');

                            $('#skuCodeBox').hide();
                            $('#skuCode').val('');
                            $('#skuCode').removeAttr('lay-verify');


                        } else if (d.value == "specialClass") { // 专类存储
                            $('#spaceProductTypeBox').show();
                            $('#spaceProductType').attr('lay-verify', "required");

                            $('#principalBox').hide();
                            $('#principal').val('');
                            $('#principal').removeAttr('lay-verify');

                            $('#skuCodeBox').hide();
                            $('#skuCode').val('');
                            $('#skuCode').removeAttr('lay-verify');

                        }else if(d.value=='sku'){

                            $('#skuCodeBox').show();
                            $('#skuCode').attr('lay-verify', "required");

                            $('#spaceProductTypeBox').hide();
                            $('#spaceProductType').val('');
                            $('#spaceProductType').removeAttr('lay-verify');

                            $('#principalBox').hide();
                            $('#principal').val('');
                            $('#principal').removeAttr('lay-verify');

                        }else {
                            // 公共存储   报修存储   回收报废存储
                            $('#spaceProductTypeBox').hide();
                            $('#spaceProductType').val('');
                            $('#spaceProductType').removeAttr('lay-verify');
                            $('#principalBox').hide();
                            $('#principal').val('');
                            $('#principal').removeAttr('lay-verify');

                            $('#skuCodeBox').hide();
                            $('#skuCode').val('');
                            $('#skuCode').removeAttr('lay-verify');

                        }
                    })*/

                }
            });

            form.on('submit(supplyParametersModifyFormbtn)', function (d) {
               /* if(d.field.principal!=''){
                    d.field.principalName=$("#principal option:selected").text();
                }else{
                    d.field.principalName='';
                }*/
                let allNewData = Object.assign(data, d.field);
                admin.req('enterprisecab/cabinet/admin/cabinetCargoSpace/update', allNewData, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        layer.close(supplyParametersModifyFormPopup);
                        table.reload('temporaryStorageCabinetFormTable');
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'PUT', 'true');
            })
        }

        //显示物料弹窗
        function showProductForm(data) {
            admin.open({
                type: 1,
                area: '1640px',
                offset: '65px',
                title: '物料列表',
                content: $('#productForm').html(),
                success: function () {
                    var cabNature = data.cabinetNature;
                    var cabType=data.cabinetType;
                    var queryFlag = undefined;
                    var url = '';
                    if(cabType=='spring'){
                        url = config.base + 'enterprisecab/cabinet/admin/cellSingleInventoryProduct/listAlarm?cabCode=' + data.code;
                        if (cabNature == 'main') {
                            queryFlag = 'mainCab'
                            url = config.base + 'enterprisecab/cabinet/admin/cellSingleInventoryProduct/list4MainCab?mainCabCode=' + data.cabCode + '&queryFlag=' + queryFlag + '&cabinetNature=sale';
                        }
                    }else{
                        url = config.base + 'enterprisecab/wcabinet/admin/wcabCellSingleInventoryProduct/list4ChildCab?cabCode=' + data.code;
                        if (cabNature == 'main') {
                            queryFlag = 'mainCab'
                            url = config.base + 'enterprisecab/wcabinet/admin/wcabCellSingleInventoryProduct/list4MainCab?mainCabCode=' + data.cabCode + '&queryFlag=' + queryFlag + '&cabinetNature=sale';
                        }
                    }

                    form.render();
                    var productTb = table.render({
                        elem: '#productTable',
                        url: url,
                        page: true,
                        // cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers', title: '序号'}
                            // , {field: 'id', title: 'ID', sort: true}
                            , {
                                field: 'skuPic', title: '物料图片', templet: function (d) {
                                    return "<img src='" + d.skuPic + "'/>"
                                }
                            }
                            , {field: 'productName', title: '物料系列名称'}
                            ,  {field: 'skuCode', title: '物料编号'}
                            , {field: 'productBrandName', title: '品牌'}
                            , {field: 'quantity', title: '当前库存'}
                            , {field: 'alarmStock', title: '告警库存'}
                            , {field: 'planReplenishment', title: '补货目标线'}
                            , {field: 'proposalStock', title: '询问线'}
                            // , {field: 'cargoLaneNum', title: '	货位数量'}
                            // , {
                            //     field: '', title: '	库存状态', templet: function (d) {
                            //         return d.quantity > d.alarmStock ? "正常" : "补货"
                            //     }
                            // }
                            // , {field: '', title: '	截至时间'}
                            , {toolbar: '#productTableBar', title: '操作', width: 210}

                        ]],
                        parseData: function (res) {
                            res.data.forEach(item => {
                                item.cabinetNature = data.cabinetNature
                                if (cabNature == 'main') {
                                    item.cabCode = data.cabCode;
                                }
                            });
                            console.log(res);
                            return res;
                        }
                    });

                    // 工具条点击事件
                    table.on('tool(productTable)', function (obj) {
                        var dataProduct = obj.data;
                        if (obj.event === 'distributionCargoWayBtn') { //分布货位
                            var cabType = data.cabinetNature;
                            var queryFlag = undefined;
                            if (cabType == 'main') {
                                queryFlag = 'mainCab';
                                dataProduct.mainCabCode = data.cabCode;
                            }
                            dataProduct.queryFlag = queryFlag;
                            dataProduct.cabinetNature=data.cabinetNature;
                            dataProduct.cabinetType=data.cabinetType;
                            showDistributionCargoWay(dataProduct)
                        } else if (obj.event === 'alarmSettingBtn') {  // 告警设置
                            showAlarmSetting(dataProduct);
                        } else if (obj.event === 'loadingShelvesBtn') { // 上货
                            showLoadingShelves(dataProduct)
                        }
                    })
                }
            })
        }

        // 显示分布货位
        function showDistributionCargoWay(data) {
            admin.open({
                type: 1,
                area: '1340px',
                offset: '100px',
                title: '物料列表',
                content: $('#distributionCargoWay').html(),
                success: function () {
                    var cabNature = data.cabinetNature;
                    var cabType=data.cabinetType;
                    var url = '';
                    if(cabType=='spring'){
                        url = config.base + 'enterprisecab/cabinet/admin/cellInventorySpace/list?cabCode=' + data.cabCode + '&skuCode4Detail=' + data.skuCode;
                        if (cabNature == 'main') {
                            url = config.base + 'enterprisecab/cabinet/admin/cellInventorySpace/list?mainCabCode=' + data.mainCabCode + '&skuCode4Detail=' + data.skuCode + '&queryFlag=mainCab&cabinetNature=sale';
                        }
                    }else{
                        url = config.base + 'enterprisecab/wcabinet/admin/wcabCellInventorySpace/list?cabCode=' + data.cabCode + '&skuCode4Detail=' + data.skuCode;
                        if (cabNature == 'main') {
                            url = config.base + 'enterprisecab/wcabinet/admin/wcabCellInventorySpace/list?mainCabCode=' + data.mainCabCode + '&skuCode4Detail=' + data.skuCode + '&queryFlag=mainCab&cabinetNature=sale';
                        }
                    }

                    form.render();
                    var productTb = table.render({
                        elem: '#distributionCargoWayTable',
                        // url: config.base + 'enterprisecab/cabinet/app/cellSingleInventoryProduct/list?cabCode=' + data.cabCode,
                        url: url,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers', title: '序号'}
                            , {field: 'spaceCode', title: '货位', sort: true}
                            , {field: 'cabCode', title: '柜子编号'}
                            , {field: 'skuName', title: '物料名称'}
                            ,  {field: 'skuCode', title: '物料编号'}
                            , {field: 'productBrandName', title: '品牌'}
                            , {field: 'quantity', title: '数量'}
                            // , {field: '', title: '备注'}
                            // , {field: 'status', title: '货位状态'}
                            // , {field: '', title: '截至时间'}
                        ]],
                    })
                }
            })
        }

        // 显示告警设置
        function showAlarmSetting(data) {
            var alarmSettingPopup = admin.open({
                type: 1,
                area: '1340px',
                offset: '100px',
                title: '告警设置',
                content: $('#alarmSetting').html(),
                success: function (_data) {
                    if (data.thresholdBlack===0){
                        data.thresholdBlack=""
                    }
                    form.val('alarmSettingForm', data);

                    $("#gjsz_cabCode").text(data.cabCode);
                    $("#gjsz_setTime").text(getNowFormatDate());
                    // $("#gjsz_location").text('')
                    $("#gjsz_productName").text(data.productName);
                    $("#gjsz_specCode").text(data.skuSpec);


                }
            });
            form.render();
            form.on('submit(alarmSettingSubBtn)', function (d) {
                let newObj = {};
                d.field.gjszCabCode = $("#gjsz_cabCode").text();
                d.field.gjszLocation = $("#gjsz_location").text();
                d.field.productName = $("#gjsz_productName").text();
                d.field.skuSpec = $("#gjsz_specCode").text();
                d.field.setTime = $("#gjsz_setTime").text();

                d.field.remarks = $("#gjsz_remarks").val();
                d.field.proposalStock = $("#gjsz_proposalStock").val();
                d.field.planReplenishment = $("#gjsz_planReplenishment").val();
                d.field.alarmStock = $("#gjsz_alarmStock").val();
                d.field.cabCode = data.cabCode;
                Object.assign(newObj, data, d.field);
                admin.req('enterprisecab/cabinet/admin/cabAlarmSettings/add', newObj, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        table.reload('productTable');
                        layer.close(alarmSettingPopup)
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'POST', 'true');


            })
        }

        // 时间
        function getNowFormatDate() {
            let date = new Date();
            let seperator1 = "-";
            let seperator2 = ":";
            let year = date.getFullYear();
            let month = date.getMonth() + 1;
            let strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            let currentdate = year + seperator1 + month + seperator1 + strDate
                + " " + date.getHours() + seperator2 + date.getMinutes()
                + seperator2 + date.getSeconds();
            return currentdate;
        }


        // 显示上货弹窗
        function showLoadingShelves(data) {
            admin.open({
                type: 1,
                area: '1340px',
                offset: '100px',
                title: '上货',
                content: $('#loadingShelves').html(),
                success: function (_data) {
                    form.val('loadingShelvesForm', data);
                    $("#sh_number").html(data.cabCode);
                    $('#sh_openingTime').html(getNowFormatDate());
                    $('#sh_completionTime').html(data.createTime);
                    admin.req('enterprisecab/cabinet/admin/cabinetCargoLane/getMyCabinetCargoLane?cabCode=' + data.cabCode + "&skuCode=" + data.skuCode, {}, function (res) {
                        if (res.code == 200) {
                            //loadSelectHtml(res.data, "请选择", "loadingShelvesSpaceCode", 4)
                        }
                    }, 'GET', false);

                }
            });


            form.render();
            form.on('submit(loadingShelvesSubBtn)', function (d) {

                let newObj = {};
                d.field.shNumber = $("#sh_number").text();
                d.field.shLocation = $("#sh_location").text();
                d.field.createrName = $("#sh_distributionClerk").text();
                d.field.shOpeningTime = $("#sh_openingTime").text();
                d.field.createTime = $("#sh_completionTime").text();
                d.field.type = 'in';

                Object.assign(newObj, d.field, data);


                admin.req('enterprisecab/cabinet/admin/cellInventoryIn/add', newObj, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        layer.closeAll('page');
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'POST', 'true');

            })


        }

        // 渲染下拉框数据
        function loadSelectHtml(data, tips, htmltarget, type) {
            let html = ' <option value>' + tips + '</option>';
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                if (type == 1) {
                    html += `<option value='${data[i].id}'>${data[i].companyName}</option>`;
                } else if (type == 2) {
                    html += `<option value='${data[i].skuCode}'>${data[i].skuCode}</option>`;
                } else if (type == 3) {
                    html += `<option value='${data[i].id}'>${data[i].warehouseName}</option>`;
                } else if (type == 4) {
                    html += `<option value='${data[i].id}' >${data[i].cabCode}</option>`;
                } else if (type == 5) {
                    html += `<option value='${data[i].id}' >${data[i].nickname}|${data[i].username}</option>`;
                } else if (type == 6) {
                    html += `<option value='${data[i].id}' >${data[i].name}</option>`;
                } else {
                    html += `<option value='${data[i].id}'>${data[i].name}</option>`;
                }
            }
            $("form select[name='" + htmltarget + "']").html(html);
            form.render('select');
        }


        // 显示订单弹窗
        function showOrder(data) {
            var cabNature = data.cabinetNature;
            var cabType=data.cabinetType;
            var queryFlag = undefined;
            var url = '';
            if(cabType=='spring'){
                url = config.base + 'enterprisecab/cabinet/admin/cellInventoryOut/list?cabCode=' + data.code;
                if (cabNature == 'main') {
                    queryFlag = 'mainCab'
                    url = config.base + 'enterprisecab/cabinet/admin/cellInventoryOut/list?mainCabCode=' + data.cabCode + '&queryFlag=' + queryFlag + '&cabinetNature=sale';
                }
            }else{
                url = config.base + 'enterprisecab/wcabinet/admin/wcabCellInventoryOut/list?cabCode=' + data.code;
                if (cabNature == 'main') {
                    queryFlag = 'mainCab'
                    url = config.base + 'enterprisecab/wcabinet/admin/wcabCellInventoryOut/list?mainCabCode=' + data.cabCode + '&queryFlag=' + queryFlag + '&cabinetNature=sale';
                }
            }
            admin.open({
                type: 1,
                area: ['1680px', '800px'],
                offset: '65px',
                title: '领用订单列表',
                content: $('#orderForm').html(),
                success: function () {
                    form.render();
                    var orderTable = table.render({
                        elem: '#orderTable',
                        // url: config.base + 'enterprisecab/cabinet/admin/cellInventoryIn/listPage?sort=create_time&order=desc&type=out',
                        url:url,
                        page: true,
                        // cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers'}

                            ,{field: 'code', sort: true, title: '领用记录编号'}
                            ,{field: 'cabCode', sort: true, title: '柜子编号'}
                            ,{field: 'spaceCode', sort: true, title: '货位编号'}
                            ,{field: 'skuName', sort: true, title: '物料名称'}
                            ,{field: 'skuCode', sort: true, title: '物料编号'}
                            ,{field: 'skuSpecOld', sort: true, title: '规格编号'}
                            // ,{field: 'deviceCode', sort: true, title: '机台'}
                            ,{field: 'weight', sort: true, title: '重量',templet:function (d) {
                                    if(d.weight<0){
                                        return d.weight*-1;
                                    }
                                    return d.weight;
                                }}
                            ,{field: 'weightUnitDesc', sort: true, title: '重量单位'}
                            ,{field: 'quantity', sort: true, title: '数量',templet:function (d) {
                                    if(d.quantity<0){
                                        return d.quantity*-1;
                                    }
                                    return d.quantity;
                                }}
                            ,{field: 'quantityUnitDesc', sort: true, title: '数量单位'}
                            ,{field: 'creatorName', sort: true, title: '领取人'}
                            ,{field: 'createTime', sort: true, title: '领取时间'}

                            // , {toolbar: '#orderTableBar', title: '操作', width: 65}
                        ]],
                    });
                    form.on('submit(orderSearchBtn)', function (data) {
                        orderTable.reload({where: data.field, page: {curr: 1}}, 'data');
                        return false;
                    })
                }
            });
            table.on('tool(orderTable)', function (obj) {
                let data = obj.data;
                if (obj.event === 'orderDetailsBtn') {
                    showOrderDetails(data);
                }
            })
        }

        // 显示订单详情弹窗
        /**
        function showOrderDetails(data) {
            admin.open({
                type: 1,
                area: ['1200px', '700px'],
                offset: '100px',
                title: '领用订单列表详情',
                content: $('#orderDetails').html(),
                success: function (_data) {

                    console.log(data);
                    $('#ddxq_marketPrice').text('￥' + data.marketPrice + '元'); // 市场价
                    $('#ddxq_quantity').text(Math.abs(data.quantity) + '件');
                    $('#ddxq_productName').text(data.productName);
                    $('#ddxq_companyName').text(data.companyName);
                    $('#ddxq_cabCode').text(data.cabCode);
                    $('#ddxq_modifier').text(data.modifier);
                    $('#ddxq_createTime').text(data.createTime);
                    // $('#ddxq_status').text(data.status);
                    $('#ddxq_code').text(data.code);

                    $('#ddxq_skuCode').text(data.skuCode);
                    $('#ddxq_skuSpec').text(data.skuSpec);
                    $('#ddxq_skuSpecOld').text(data.skuSpecOld);
                    $('#ddxq_skuCode').text(data.skuCode);
                    $('#ddxq_spaceCode').text(data.spaceCode);
                    $('#ddxq_creatorName').text(data.creatorName);
                    $('#ddxq_skuPic').html('<img src="' + data.skuPic + '" style="width: auto; height: 40px;"/>');


                }
            });
        }*/

        function showOrderDetails(data) {
            admin.open({
                type: 1,
                area: ['1200px', '700px'],
                offset: '100px',
                title: '领用订单列表详情',
                content: $('#orderDetails').html(),
                success: function (_data) {



                }
            });
        }

        //  权限弹窗
        /*function  showPermissions(_data) {
            let toolCabinetTableData = _data;
            admin.open({
                type: 1,
                area: ['1500px', '800px'],
                offset: '65px',
                title: '设备权限管理',
                content: $('#permissionsForm').html(),
                success: function (_data) {
                    let permissionsFormTB = table.render({
                        elem: '#permissionsTable',
                        url: config.base + 'enterprisecab/cabinet/admin/authorityManage/list?cabinetId='+toolCabinetTableData.id,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'checkbox'}
                            //,{type: 'numbers' , title: '序号'}
                            ,{field: 'name', title: '权限组名称', width :220}
                            ,{field: 'quantity', title: '人员数量', width :100}
                            ,{field: 'lineOfCredit', title: '授信额度',templet:d=> d.lineOfCredit+"元/"+d.lineEvaluatePeriodDesc, width :250}
                            ,{field: 'remark', title: '说明' ,width :300}
                            ,{field: 'status', title: '状态', width :100, templet:d=> d.status=='0'?'正常':'禁用'}
                            ,{field: 'createTime', title: '创建时间', width :160}
                            ,{toolbar: '#permissionsFormTableBar', title: '操作',width :240}
                        ]],
                    });
                    // 工具条点击事件
                    table.on('tool(permissionsTable)', function (obj) {
                        let data = obj.data;
                        if (obj.event === 'details') { //详情
                            showAddPermissionsGroupForm(data,false,'details');
                        }else if(obj.event === 'modify'){ // 修改
                            showAddPermissionsGroupForm(data,false,'modify');
                        } else if (obj.event === 'member') {  // 成员管理
                            showMemberForm(data)
                        }else if (obj.event === 'disable'){ // 禁用
                            enableAndDisable('1', data)
                        }else if (obj.event === 'enable'){  //  启用
                            enableAndDisable('0', data)
                        }
                    });

                    function enableAndDisable(_type,_data){
                        layer.load(2);
                        admin.req('enterprisecab/cabinet/admin/authorityManage/enable/'+_data.id+'/'+_type, {}, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('permissionsTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'PUT');
                    }

                    $('#addPermissionsGroupBtn').click(function () { // 添加权限组
                        showAddPermissionsGroupForm(false,toolCabinetTableData)
                    });
                    $('#permissionsExport').click(function() {  //导出
                        let checkRows = table.checkStatus('permissionsTable');
                        if (checkRows.data.length == 0) {
                            layer.msg('请选择要导出的数据', {icon: 2});
                        } else {
                            table.exportFile(permissionsFormTB.config.id, checkRows.data, 'xls');
                        }
                    })
                }
            })
        }*/

        //  添加权限组
       /* function showAddPermissionsGroupForm(data,cabinetData,_type) {
            let addPermissionsGroupPopUp = admin.open({
                type: 1,
                area: ['800px', '700px'],
                offset: '85px',
                title: data? '权限组详情': '添加权限组',
                content: $('#addPermissionsGroupForm').html(),
                success: function (_data) {
                    let arr2treeExt;
                    let selectedData = function (treeData, targetId) {
                        for (var k = 0; k < treeData.length; k++) {
                            var nodeId = treeData[k].id;
                            if (targetId == nodeId) {
                                treeData[k].selected = true;
                                return;
                            } else {
                                if (treeData[k].children && treeData[k].children != '') {
                                    selectedData(treeData[k].children, targetId);
                                }
                            }
                        }
                    };
                    admin.req('enterprise/product/admin/productCategory/list?limit=9999&enterprise=0&page=1', {}, function (res) {
                        for (let i = 0; i < res.data.length; i++) {
                            res.data[i].children = [];
                        }
                        arr2treeExt = xmSelect.arr2tree(res.data, "parentId", "id", "children", -1);
                    }, 'get', false);

                    let selectedDataExt = function (treeData, targetId) {
                        var ids = targetId.split(",");
                        for (var k = 0; k < treeData.length; k++) {
                            var nodeId = treeData[k].id;
                            for (var t = 0; t < ids.length; t++) {
                                if (ids[t] == nodeId) {
                                    treeData[k].selected = true;
                                    continue;
                                } else {
                                    if (treeData[k].children && treeData[k].children != '') {
                                        selectedData(treeData[k].children, ids[t]);
                                    }
                                }
                            }
                        }
                    };

                    if(data){
                        data.status = data.status== 0 ? 'on' : '';
                        if (_type == 'details') {
                            $('[lay-filter="addPermissionsGroupForm"] input').attr('disabled','disabled');
                            $('[lay-filter="addPermissionsGroupForm"] select').attr('disabled','disabled');
                            $('[lay-filter="addPermissionsGroupForm"] input').css('borderColor','transparent');
                            $('button[lay-filter="addPermissionsGroupFormSubmit"]').hide();
                        }else {
                            $('[lay-filter="addPermissionsGroupForm"] input[name="name"]').attr('disabled','disabled');
                            form.on('select(creditWay)', function(data){
                                if (data.value === 'unlimited') {
                                    $('#lineOfCreditBox').css('display','none');
                                    $('#lineOfCredit').removeAttr('lay-verify');
                                    $('#lineOfCredit').val('');
                                }else {
                                    $('#lineOfCreditBox').css('display','block');
                                    $('#lineOfCredit').remove('lay-verify','number');
                                }
                            });
                            form.on('select(astrictMaterial)', function(data){
                                if (data.value === 'noAstrict') {
                                    $('#materialIdBox').css('display', 'none');
                                    $('input[name="materialId"]').val('');
                                    smlSelectInstansExt.setValue([ ]);
                                    $('input[name="materialId"]').remove('lay-verify');
                                }else {
                                    $('#materialIdBox').css('display', 'block');
                                    $('input[name="materialId"]').removeAttr('lay-verify');
                                }
                            });
                            // 提交
                            form.on('submit(addPermissionsGroupFormSubmit)', function(d){
                                // layer.load(2);
                                d.field.cabinetId = cabinetData.id;
                                d.field.status = d.field.status=='on' ? 0 : 1;

                                admin.req('enterprisecab/cabinet/admin/authorityManage/update', d.field, function (res) {
                                    layer.closeAll('loading');
                                    if (res.code == 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('permissionsTable');
                                        layer.close(addPermissionsGroupPopUp);
                                    } else {
                                        layer.msg(res.msg, {icon: 2});
                                    }
                                }, 'PUT');
                                return false
                            });
                        }

                        form.val('addPermissionsGroupForm', data);
                        if (data.creditWay === 'unlimited') {
                            $('#lineOfCreditBox').css('display','none');
                            $('#lineOfCredit').removeAttr('lay-verify');
                            $('#lineOfCredit').val('');
                        }else {
                            $('#lineOfCreditBox').css('display','block');
                            $('#lineOfCredit').remove('lay-verify','number');
                        }

                        if (data.astrictMaterial === 'noAstrict') {
                            $('#materialIdBox').css('display', 'none');
                            $('input[name="materialId"]').val('');
                            // smlSelectInstansExt.setValue([ ]);
                            $('input[name="materialId"]').remove('lay-verify');
                        }else {
                            $('#materialIdBox').css('display', 'block');
                            $('input[name="materialId"]').removeAttr('lay-verify');
                        }

                        selectedDataExt(arr2treeExt, data.materialId);

                    }else {
                        form.on('select(creditWay)', function(data){
                            if (data.value === 'unlimited') {
                                $('#lineOfCreditBox').css('display','none');
                                $('#lineOfCredit').removeAttr('lay-verify');
                                $('#lineOfCredit').val('');
                            }else {
                                $('#lineOfCreditBox').css('display','block');
                                $('#lineOfCredit').remove('lay-verify','number');
                            }
                        });
                        form.on('select(astrictMaterial)', function(data){
                            if (data.value === 'noAstrict') {
                              $('#materialIdBox').css('display', 'none');
                              $('input[name="materialId"]').val('');
                              smlSelectInstansExt.setValue([ ]);
                              $('input[name="materialId"]').remove('lay-verify');
                            }else {
                                $('#materialIdBox').css('display', 'block');
                                $('input[name="materialId"]').removeAttr('lay-verify');
                            }
                        });

                        // 提交
                        form.on('submit(addPermissionsGroupFormSubmit)', function(d){
                            layer.load(2);
                            d.field.cabinetId = cabinetData.id;
                            d.field.status = d.field.status=='on' ? 0 : 1;
                            admin.req('enterprisecab/cabinet/admin/authorityManage/add', d.field, function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    table.reload('permissionsTable');
                                    layer.close(addPermissionsGroupPopUp);
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'POST');
                            return false
                        });
                    }
                    let smlSelectInstansExt = xmSelect.render({
                        el: '#materialId',
                        model: {label: {type: 'text'}},
                        clickClose: true,
                        filterable: true,
                        disabled: data?_type =='details'?true:false : false,
                        tree: {
                            show: true,
                            strict: false,
                            expandedKeys: [-1],
                        },
                        tips: '顶级分类',
                        prop: {
                            name: 'name',
                            value: 'id',
                            children: 'children'
                        },
                        data() {
                            //填充数据
                            return arr2treeExt;
                        },
                        on: function (data) {
                            let id = '';
                            for (var j = 0; j < data.arr.length; j++) {
                                if (j == 0) {
                                    id = data.arr[j].id
                                } else {
                                    id += ',' + data.arr[j].id;
                                }
                            }
                            $("input[name='materialId']").val(id)
                        }
                    });


                    form.render("select");
                    form.render("checkbox");
                }
            })
        }*/

        /*function showMemberForm(data){
            admin.open({
                type: 1,
                area: ['1400px', '700px'],
                offset: '75px',
                title: '设备权限组成员管理',
                content: $('#memberForm').html(),
                success: function (_data) {
                    let permissionsData = data;
                    let memberFormTB = table.render({
                        elem: '#memberFormTable',
                        url: config.base + 'enterprisecab/cabinet/admin/authorityMember/list?authorityManageId='+data.id,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'checkbox'}
                            , {field: 'userName', title: '成员姓名'}
                            , {field: 'jobNumber', title: '工号'}
                            , {field: 'phone', title: '电话'}
                            , {field: 'enterpriseName', title: '所属公司'}
                            , {field: 'deptName', title: '所属部门'}
                            , {field: 'positionName', title: '所属岗位'}
                            , {field: '', title: '所属权限组(以主柜面板为单位)',templet:d=> data.name}
                            , {field: 'isDeleted', title: '状态',templet:d=> d.isDeleted?'正常':'禁用'}
                            , {field: 'createTime', title: '创建时间'}
                            , {field: 'creatorName', title: '添加人'}
                            , {toolbar: '#memberFormTableBar', title: '操作'}
                        ]],
                    });

                    // 工具条点击事件
                    table.on('tool(memberFormTable)', function (obj) {
                        let data = obj.data;
                        if (obj.event === 'details') { //详情
                            showAddPermissionGroupMembersForm('details',Object.assign(permissionsData,data));
                        } else if (obj.event === 'delete') {  //删除
                            layer.load(2);
                            admin.req('enterprisecab/cabinet/admin/authorityMember/'+data.id,{},res => {
                               layer.closeAll('loading');
                               if (res.code == 200) {
                                   layer.msg(res.msg, {icon: 1});
                                   table.reload('memberFormTable');
                               } else {
                                   layer.msg(res.msg, {icon: 2});
                               }
                            },'DELETE')
                        }
                    });


                    $('#memberFormBatchDeletion').click(function () { // 批量操作
                        let checkRows = table.checkStatus('memberFormTable');
                        if (checkRows.data.length == 0) {
                            layer.msg('请选择要删除的数据', {icon: 2});
                        } else {
                            new Promise((resolve, reject) => {
                                let  ids= '';
                                checkRows.data.forEach(item => {ids += item.id + ','});
                                resolve(ids.substr(0, ids.length - 1));
                            }).then(rData => {
                                layer.load(2);
                                admin.req('enterprisecab/cabinet/admin/authorityMember/batchIds',{ids:rData.split(',')},res => {
                                    layer.closeAll('loading');
                                    if (res.code == 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('memberFormTable');
                                    } else {
                                        layer.msg(res.msg, {icon: 2});
                                    }
                                },'DELETE')
                            });
                        }
                    });
                    $('#addMembersBtn').click(function () { // 添加权限组成员
                        showAddPermissionGroupMembersForm('add',data)
                    });

                    $('#memberFormExport').click(function() {  //导出
                        let checkRows = table.checkStatus('memberFormTable');
                        if (checkRows.data.length == 0) {
                            layer.msg('请选择要导出的数据', {icon: 2});
                        } else {
                            table.exportFile(memberFormTB.config.id, checkRows.data, 'xls');
                        }
                    })

                }
            })
        }*/

        //  添加权限组成员
        /*function showAddPermissionGroupMembersForm(_type,data) {
            let addPermissionGroupMembersPopUp =admin.open({
                type: 1,
                area: ['800px', '750px'],
                offset: '85px',
                title: _type==='details'? '权限组详情': '添加权限组',
                content: $('#addPermissionGroupMembers').html(),
                success: function (_data) {
                    let enterpriseName='',deptName = '',positionName ='',userName= '';

                    let arr2treeExt;
                    let selectedData = function (treeData, targetId) {
                         for (var k = 0; k < treeData.length; k++) {
                             var nodeId = treeData[k].id;
                             if (targetId == nodeId) {
                                 treeData[k].selected = true;
                                 return;
                             } else {
                                 if (treeData[k].children && treeData[k].children != '') {
                                     selectedData(treeData[k].children, targetId);
                                 }
                             }
                         }
                     };
                    // enterprise/product/admin/productCategory/list?limit=9999&enterprise=0&page=1
                    admin.req('enterprise/knife/admin/productCategoryKnife/list?limit=9999&enterprise=0&page=1', {}, function (res) {
                        for (let i = 0; i < res.data.length; i++) {
                            res.data[i].children = [];
                        }
                        arr2treeExt = xmSelect.arr2tree(res.data, "parentId", "id", "children", -1);
                    }, 'get', false);

                     let selectedDataExt = function (treeData, targetId) {
                         var ids = targetId.split(",");
                         for (var k = 0; k < treeData.length; k++) {
                             var nodeId = treeData[k].id;
                             for (var t = 0; t < ids.length; t++) {
                                 if (ids[t] == nodeId) {
                                     treeData[k].selected = true;
                                     continue;
                                 } else {
                                     if (treeData[k].children && treeData[k].children != '') {
                                         selectedData(treeData[k].children, ids[t]);
                                     }
                                 }
                             }
                         }
                     }
                     if(data){
                         if(data.creditWay =='unlimited'){
                             $('#addPermissionGroupMembersFormLineOfCreditBox').css('display','none')
                         }else {
                             $('#addPermissionGroupMembersFormLineOfCreditBox').css('display','black')
                         }

                         if(data.astrictMaterial =='noAstrict'){
                             $('#materialId1Box').css('display','none')
                         }else {
                             $('#materialId1Box').css('display','black')
                         }
                     }
                     if (_type==='details') {
                         form.val('addPermissionGroupMembersForm', data);
                         selectedDataExt(arr2treeExt, data.materialId);
                         $('[lay-filter="addPermissionGroupMembersForm"] input').attr('disabled','disabled');
                         $('[lay-filter="addPermissionGroupMembersForm"] select').attr('disabled','disabled');
                         $('[lay-filter="addPermissionGroupMembersForm"] input').css('borderColor','transparent');
                         $('button[lay-filter="addPermissionGroupMembersFormSubmit"]').hide();
                         loadSelectHtmlNew('', data.deptName, 'deptId', '[lay-filter="addPermissionGroupMembersForm"]',1);
                         loadSelectHtmlNew('', data.enterpriseName, 'enterpriseId', '[lay-filter="addPermissionGroupMembersForm"]',1)
                         loadSelectHtmlNew('', data.positionName, 'positionId', '[lay-filter="addPermissionGroupMembersForm"]',1)
                         loadSelectHtmlNew('', data.userName, 'userId', '[lay-filter="addPermissionGroupMembersForm"]',1)

                     }else {
                         data.remark = '';
                         data.jobNumber = '';
                         data.phone = '';
                         data.isDeleted = true;
                         form.val('addPermissionGroupMembersForm', data);
                         selectedDataExt(arr2treeExt, data.materialId);
                         admin.req('user/admin/companyInfo/list?limit=9999', {}, res => {
                             if (res.code == '200') {
                                 loadSelectHtmlNew(res.data, '请选择企业', 'enterpriseId', '[lay-filter="addPermissionGroupMembersForm"]',1)
                             }
                         }, 'GET');

                         form.on('select(enterpriseId)', function(data){
                             if (data.value != '') {
                                 admin.req('user/admin/department/list?limit=9999&companyInfoId='+data.value, {}, res => {
                                     enterpriseName = data.elem[data.elem.selectedIndex].text;
                                     if (res.code == '200') {
                                         loadSelectHtmlNew(res.data, '请选择选择部门', 'deptId', '[lay-filter="addPermissionGroupMembersForm"]',1);
                                         loadSelectHtmlNew('', '请选择岗位', 'positionId', '[lay-filter="addPermissionGroupMembersForm"]',1);
                                         loadSelectHtmlNew('', '请选择人员', 'userId', '[lay-filter="addPermissionGroupMembersForm"]',2);
                                         $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val('');
                                         $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val('')
                                     }else {
                                         layer.msg(res.msg, {icon: 2});
                                         loadSelectHtmlNew('', '请选择选择部门', 'deptId', '[lay-filter="addPermissionGroupMembersForm"]',1);
                                         loadSelectHtmlNew('', '请选择岗位', 'positionId', '[lay-filter="addPermissionGroupMembersForm"]',1);
                                         loadSelectHtmlNew('', '请选择人员', 'userId', '[lay-filter="addPermissionGroupMembersForm"]',2);
                                         $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val('');
                                         $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val('')
                                     }
                                 }, 'GET');
                             }else {
                                 loadSelectHtmlNew('', '请选择选择部门', 'deptId', '[lay-filter="addPermissionGroupMembersForm"]',1);
                                 loadSelectHtmlNew('', '请选择岗位', 'positionId', '[lay-filter="addPermissionGroupMembersForm"]',1);
                                 loadSelectHtmlNew('', '请选择人员', 'userId', '[lay-filter="addPermissionGroupMembersForm"]',2);
                                 $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val('');
                                 $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val('')
                             }

                         });

                         form.on('select(deptId)', function(data){
                             deptName = data.elem[data.elem.selectedIndex].text;
                             if (data.value != '') {
                                 admin.req('user/admin/role/list?limit=9999&departmentId='+data.value, {}, res => {
                                     if (res.code == '200') {
                                         loadSelectHtmlNew(res.data, '请选择岗位', 'positionId', '[lay-filter="addPermissionGroupMembersForm"]',1);
                                         loadSelectHtmlNew('', '请选择人员', 'userId', '[lay-filter="addPermissionGroupMembersForm"]',2);
                                         $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val('');
                                         $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val('')
                                     }else {
                                         layer.msg(res.msg, {icon: 2});
                                     }
                                 }, 'GET');
                             }else {
                                 loadSelectHtmlNew('', '请选择岗位', 'positionId', '[lay-filter="addPermissionGroupMembersForm"]',1);
                                 loadSelectHtmlNew('', '请选择人员', 'userId', '[lay-filter="addPermissionGroupMembersForm"]',2);
                                 $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val('');
                                 $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val('')
                             }
                         });

                         form.on('select(positionId)', function(data){
                             positionName = data.elem[data.elem.selectedIndex].text;
                             if (data.value != '') {
                                 admin.req('user/admin/user/getUserByPostId?limit=9999&postId='+data.value, {}, res => {
                                     if (res.code == '200') {
                                         loadSelectHtmlNew(res.data, '请选择人员', 'userId', '[lay-filter="addPermissionGroupMembersForm"]',2);
                                         $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val('');
                                         $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val('')
                                     }else {
                                         layer.msg(res.msg, {icon: 2});
                                     }
                                 }, 'GET');
                             }else {
                                 loadSelectHtmlNew('', '请选择人员', 'userId', '[lay-filter="addPermissionGroupMembersForm"]',2);
                                 $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val('');
                                 $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val('')
                             }
                         });

                         form.on('select(userId)', function(data){
                             userName = data.elem[data.elem.selectedIndex].text;
                             if (data.value != '') {
                                 admin.req('enterprisecab/cabinet/admin/authorityMember/getAuthorityMemberByUserId?id='+data.value, {}, res => {
                                     if (res.code == '200') {
                                         $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val(res.data.data.phone);
                                         $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val(res.data.data.username)
                                     }else {
                                         layer.msg(res.msg, {icon: 2});
                                         $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val('');
                                         $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val('');
                                         $('form[lay-filter="addPermissionGroupMembersForm"] select[name="userId"]').val('');
                                         form.render();
                                     }
                                 }, 'GET');
                             }else {
                                 $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val('');
                                 $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val('')
                             }
                         });

                         // 提交
                         form.on('submit(addPermissionGroupMembersFormSubmit)', function(d){
                             layer.load(2);
                             d.field.authorityManageId = data.id;
                             d.field.userName = userName;
                             d.field.positionName = positionName;
                             d.field.deptName = deptName;
                             d.field.enterpriseName = enterpriseName;

                             admin.req('enterprisecab/cabinet/admin/authorityMember/add', d.field, function (res) {
                                 layer.closeAll('loading');
                                 if (res.code == 200) {
                                     layer.msg(res.msg, {icon: 1});
                                     table.reload('memberFormTable');
                                     layer.close(addPermissionGroupMembersPopUp);
                                 } else {
                                     layer.msg(res.msg, {icon: 2});
                                 }
                             }, 'POST');
                             return false
                         });

                     }
                    let smlSelectInstansExt = xmSelect.render({
                        el: '#materialId1',
                        model: {label: {type: 'text'}},
                        clickClose: true,
                        filterable: true,
                        disabled: true,
                        tree: {
                            show: true,
                            strict: false,
                            expandedKeys: [-1],
                        },
                        tips: '顶级分类',
                        prop: {
                            name: 'name',
                            value: 'id',
                            children: 'children'
                        },
                        data() {
                            //填充数据
                            return arr2treeExt;
                        },
                        on: function (data) {
                            let id = '';
                            for (var j = 0; j < data.arr.length; j++) {
                                if (j == 0) {
                                    id = data.arr[j].id
                                } else {
                                    id += ',' + data.arr[j].id;
                                }
                            }
                            $("form[lay-filter='addPermissionGroupMembersForm'] input[name='materialId']").val(id)
                        }
                    });

                    form.render("select");
                    form.render("checkbox");
                }
            })
        }*/

        function loadSelectHtmlNew(data, tips, htmltarget, formName,type) {
            let html = '';
            if(tips){
                html = '<option value>' + tips + '</option>'
            }
            if (!data || data == null) {
                $("form"+formName+" select[name='" + htmltarget + "']").html(html);
                form.render('select');
                return ;
            }
            for (let i = 0; i < data.length; i++) {
                if (type == 1) {
                    html += `<option value='${data[i].id}'>${data[i].name}</option>`;
                }else if(type == 2){
                    html += `<option value='${data[i].id}'>${data[i].nickname}</option>`;
                }else if (type == 3) {
                    html += `<option value='${data[i].value}'>${data[i].name}</option>`;
                }else if(type == 7){
                    html += `<option value='${data[i].id}' data='${JSON.stringify(data[i])}'>${data[i].nickname}</option>`;
                }
            }
            $("form"+formName+" select[name='" + htmltarget + "']").html(html);
            form.render('select');
        }

        let cabinetId;
        // 权限
        /*主柜权限弹窗*/
        function mainCabinetAuthorityFun(data) {
            cabinetId = data.id;
           let mainCabinetAuthorityPop = admin.open({
                type: 1,
                area: ['1200px', '810px'],
                offset: '65px',
                title: '设备权限管理',
                content: $('#mainCabinetAuthorityForm').html(),
                success: function () {
                    let mainCabinetAuthorityTb = table.render({
                        elem: '#mainCabinetAuthorityTable',
                        url: config.base + 'enterprisecab/wcabinet/admin/wauthorityManage/list?cabinetId=' + data.id,
                        page: true,
                        cellMinWidth: 100,
                        title:'设备权限组列表',
                        id: 'mainCabinetAuthorityTable',
                        cols: [[
                            {type: 'checkbox'}
                            , {field: 'name', title: '权限组名称'}
                            , {field: 'quantity', title: '人员数量'}
                            , {field: 'remark', title: '说明'}
                            , {field: 'status', title: '状态', templet: d => d.status == '0' ? '正常' : '禁用'}
                            , {field: 'createTime', title: '创建时间'}
                            , {toolbar: '#mainCabinetAuthorityFormTableBar', title: '操作', width: 300}
                        ]],
                        done: function (d) {
                        }
                    });

                    table.on('tool(mainCabinetAuthorityTable)', function (obj) {
                        let data = obj.data;
                        if (obj.event === 'details') { //详情
                            showAddPermissionsGroupForm(data, '', 'details');
                        } else if (obj.event === 'modify') { // 修改
                            showAddPermissionsGroupForm(data, '', 'modify');
                        } else if (obj.event === 'member') {  // 成员管理
                            showMemberForm(data)
                        } else if (obj.event === 'disable') { // 禁用
                            enableAndDisable('1', data)
                        } else if (obj.event === 'enable') {  //  启用
                            enableAndDisable('0', data)
                        }else if(obj.event === 'delete'){
                            layer.confirm('确定删除吗？', {
                                skin: 'layui-layer-admin'
                            }, function (i) {
                                layer.close(i);
                                layer.load(2);
                                admin.req('enterprisecab/wcabinet/admin/wauthorityManage/' + data.id, {}, function (data) {
                                    layer.closeAll('loading');
                                    if (data.code == 200) {
                                        layer.msg(data.msg, {icon: 1});
                                        table.reload('mainCabinetAuthorityTable');
                                        layer.close(i);
                                    } else {
                                        layer.msg(data.msg, {icon: 2});
                                    }
                                }, 'DELETE');
                            });
                        }
                    });

                    function enableAndDisable(_type, _data) {
                        layer.load(2);
                        admin.req('enterprisecab/wcabinet/admin/wauthorityManage/enable/' + _data.id + '/' + _type, {}, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('mainCabinetAuthorityTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'PUT');
                    }

                    $('#addPermissionsGroupBtn').click(function () { // 添加权限组
                        showAddPermissionsGroupForm(false, data)
                    });
                    $('#permissionsExport').click(function () {  //导出
                        let checkRows = table.checkStatus('mainCabinetAuthorityTable');
                        if (checkRows.data.length == 0) {
                            layer.msg('请选择要导出的数据', {icon: 2});
                        } else {
                            table.exportFile(mainCabinetAuthorityTb.config.id, checkRows.data, 'xls');
                        }
                    });

                    //搜索
                    form.on('submit(mainCabinetAuthorityFormSearch)', function (data) {
                        mainCabinetAuthorityTb.reload({where: data.field, page: {curr: 1}}, 'data');
                    });

                }
            });
        }


        // (添加、修改、详情)权限组
        function showAddPermissionsGroupForm(data, cabinetData, _type) {
            let addPermissionsGroupPopUp = admin.open({
                type: 1,
                area: ['1280px', '750px'],
                offset: '85px',
                title: _type ? (_type == 'details' ? '权限组详情' : '修改权限组') : '添加权限组',
                content: $('#addPermissionsGroupForm').html(),
                success: function (_data) {
                    let ids = undefined, categoryIds = undefined, authorityManageId = undefined;
                    let arr2treeExt;
                    let selectedData = function (treeData, targetId) {
                        for (var k = 0; k < treeData.length; k++) {
                            var nodeId = treeData[k].id;
                            if (targetId == nodeId) {
                                treeData[k].selected = true;
                                return;
                            } else {
                                if (treeData[k].children && treeData[k].children != '') {
                                    selectedData(treeData[k].children, targetId);
                                }
                            }
                        }
                    };
                    admin.req('enterprise/product/admin/productCategory/list?limit=9999&enterprise=0&page=1', {}, function (res) {
                        for (let i = 0; i < res.data.length; i++) {
                            res.data[i].children = [];
                        }
                        arr2treeExt = xmSelect.arr2tree(res.data, "parentId", "id", "children", -1);
                    }, 'get', false);

                    let selectedDataExt = function (treeData, targetId) {
                        var ids = targetId.split(",");
                        for (var k = 0; k < treeData.length; k++) {
                            var nodeId = treeData[k].id;
                            for (var t = 0; t < ids.length; t++) {
                                if (ids[t] == nodeId) {
                                    treeData[k].selected = true;
                                    continue;
                                } else {
                                    if (treeData[k].children && treeData[k].children != '') {
                                        selectedData(treeData[k].children, ids[t]);
                                    }
                                }
                            }
                        }
                    };

                    let addPermissionsGroupFormTbData = [];
                    let addPermissionsGroupFormTb = table.render({
                        elem: '#addPermissionsGroupFormTable',
                        data: addPermissionsGroupFormTbData,
                        cellMinWidth: 100,
                        limit: Number.MAX_VALUE,
                        cols: [[
                            {type: 'numbers', title: '序号', fixed: 'left'}
                            , {field: 'productPic',title: '图片',
                                templet: d => d.productPic ? '<img src="' + d.productPic + '" style="cursor: pointer"/>' : '<img src="assets/images/default-icon.png" style="cursor: pointer"/>'
                            }
                            , {field: 'skuName', title: '物料名称'}
                            , {field: 'skuCode', title: '物料编号'}
                            , {field: 'oldSpecCode', title: '物料规格'}
                            , {field: 'productBrandName', title: '所属品牌'}
                            , {field: 'unitName', title: '单位'}
                            , {align: 'center', toolbar: '#addPermissionsGroupFormTableBar', title: '操作'}
                        ]],
                        done:function (res, curr, count) {
                            if(_type == 'details'){
                                $('#addPermissionsGroupFormTableBox input').attr('disabled','disabled')
                            }
                        }
                    });

                    table.on('tool(addPermissionsGroupFormTable)', function (obj) {
                        let data = obj.data;
                        if (obj.event === 'delete') { // 删除
                            addPermissionsGroupFormTbData.splice($(obj.tr[0]).attr('data-index'),1);
                            table.reload('addPermissionsGroupFormTable', {data: addPermissionsGroupFormTbData});
                        }
                    });

                    $("#addPermissionsGroupFormTableBox").delegate("input[name='number']", "blur", function () {
                        if (addPermissionsGroupFormTbData[$(this).parents('tr').index()]) {
                            addPermissionsGroupFormTbData[$(this).parents('tr').index()].number = $(this).val();
                            addPermissionsGroupFormTbData[$(this).parents('tr').index()].amount = '';
                        }
                    });
                    $("#addPermissionsGroupFormTableBox").delegate("input[name='amount']", "blur", function () {
                        if (addPermissionsGroupFormTbData[$(this).parents('tr').index()]) {
                            addPermissionsGroupFormTbData[$(this).parents('tr').index()].amount = $(this).val();
                            addPermissionsGroupFormTbData[$(this).parents('tr').index()].number ='';
                        }
                    });


                    $('#lineOfCredit').blur(function () {
                        addPermissionsGroupFormTbData.forEach(item=>{
                            item.amount = $(this).val()
                        });

                        table.reload('addPermissionsGroupFormTable', {data: addPermissionsGroupFormTbData});
                    });

                    $('#authorizedQuantity').blur(function () {
                        addPermissionsGroupFormTbData.forEach(item=>{
                            item.number = $(this).val()
                        });
                        table.reload('addPermissionsGroupFormTable', {data: addPermissionsGroupFormTbData});
                    });


                    //限制方式操作
                    form.on('radio(materiel)', function (data) {
                        materialIdBox(data.value);
                        addPermissionsGroupAddFn(data.value);
                        isShowTable(data.value);
                    });


                    // 限制方式（显示不显示）
                    function restrictWayFn(_type){
                        if (_type === 'unlimited' || _type === 'unlimitedQuantity'){
                            $('#restrictWayBox').hide();
                            $('#restrictWayBox  input[name="restrictWay"]').removeAttr('checked');
                        }else if(_type === 'noAstrict'){
                            $('#restrictWayBox').hide();
                            $('#restrictWayBox  input[name="restrictWay"]').removeAttr('checked');
                        }else {
                            $('#restrictWayBox').show();
                            $('#restrictWayBox  input[name="restrictWay"]').eq(0).prop('checked', 'true');
                        }
                        form.render('radio');
                    }

                    let smlSelectInstansExt = xmSelect.render({
                        el: '#materialId',
                        model: {label: {type: 'text'}},
                        clickClose: true,
                        filterable: true,
                        layVerify: 'required',
                        disabled: data ? _type == 'details' ? true : false : false,
                        tree: {
                            show: true,
                            strict: false,
                            expandedKeys: [-1],
                        },
                        tips: '顶级分类',
                        prop: {
                            name: 'name',
                            value: 'id',
                            children: 'children'
                        },
                        data() {
                            //填充数据
                            return arr2treeExt;
                        },
                        on: function (data) {
                            let id = '';
                            for (var j = 0; j < data.arr.length; j++) {
                                if (j == 0) {
                                    id = data.arr[j].id
                                } else {
                                    id += ',' + data.arr[j].id;
                                }
                            }
                            $("input[name='materialId']").val(id);

                            layer.load(2);
                            admin.req('enterprisecab/wcabinet/admin/wauthorityManage/findMateriel',{page: 1, limit: 99999,categoryIds:id},res=>{
                                layer.closeAll('loading');
                                if (res.code == 200){
                                    res.data.forEach(item=>{
                                        item.manageld = '';
                                        item.id = void 0;
                                        if($('input[name="authorizedQuantity"]').val()>0){
                                            item.number = $('input[name="authorizedQuantity"]').val();
                                        }else if($('input[name="lineOfCredit"]').val()){
                                            item.amount = $('input[name="lineOfCredit"]').val();
                                        }else {
                                            item.number = '';
                                            item.amount = '';
                                        }
                                        item.colsIsShow = false;
                                    });

                                    addPermissionsGroupFormTbData = res.data;
                                    table.reload('addPermissionsGroupFormTable', {data: addPermissionsGroupFormTbData});
                                }
                            })
                        }
                    });
                    //可领物资分类（显示不显示）
                    function materialIdBox(_type){
                        if(_type === 'category'){
                            $('#materialIdBox').show();
                            smlSelectInstansExt.update({layVerify:'required'})
                        }else {
                            $('#materialIdBox').hide();
                            $('#materialIdBox input').val('');
                            smlSelectInstansExt.setValue([]);
                            smlSelectInstansExt.update({layVerify:''});
                        }
                    }

                    // 添加限制物料按钮（显示不显示）
                    function addPermissionsGroupAddFn(_type){
                        if(_type === 'materiel'){
                            $('#addPermissionsGroupAdd').show();
                        }else {
                            $('#addPermissionsGroupAdd').hide();
                        }
                    }

                    //添加限制物料
                    function addPermissionsGroupAddPup(){
                        if (addPermissionsGroupFormTbData.length>0){
                            ids ='';
                            addPermissionsGroupFormTbData.forEach((item,index)=>{
                                if ((index+1) === addPermissionsGroupFormTbData.length){
                                    ids += item.skuCode;
                                }else {
                                    ids += item.skuCode+",";
                                }
                            })
                        }

                        let addRestrictedMaterialsPopUp = admin.open({
                            type: 1,
                            area: ['1200px', '820px'],
                            offset: '65px',
                            title: '添加限制物料',
                            content: $('#addRestrictedMaterialsTemplate').html(),
                            success: function (_data) {
                                let addRestrictedMaterialsFormTb = table.render({
                                    elem: '#addRestrictedMaterialsFormTable',
                                    url: config.base + 'enterprisecab/wcabinet/admin/wauthorityManage/findMateriel',
                                    page: true,
                                    where: {ids,categoryIds},
                                    limit: 5,
                                    limits: [5, 10, 20, 30, 40, 50, 60, 70, 80],
                                    cellMinWidth: 100,
                                    cols: [[
                                        {type: 'checkbox'}
                                        , {
                                            field: 'productPic',
                                            title: '图片',
                                            templet: d => d.productPic ? '<img src="' + d.productPic + '" style="cursor: pointer"/>' : '<img src="assets/images/default-icon.png"/>'
                                        }
                                        , {field: 'skuName', title: '物料名称'}
                                        , {field: 'skuCode', title: '物料编号'}
                                        , {field: 'oldSpecCode', title: '物料规格'}
                                        // , {field: 'packName', title: '包装规格'}
                                        , {field: 'productBrandName', title: '所属品牌'}
                                        , {field: 'unitName', title: '单位'}
                                    ]],
                                });


                                $('#addRestrictedMaterialsFormSubmit').click(function () {
                                    let checkStatus = table.checkStatus('addRestrictedMaterialsFormTable');
                                    if (checkStatus.data.length === 0) {
                                        layer.msg('请选择需要导出的数据', {icon: 5});
                                        return false;
                                    }
                                    checkStatus.data.forEach(item=>{
                                        item.manageld = '';
                                        item.id = void 0;
                                        if($('input[name="authorizedQuantity"]').val()>0){
                                            item.number = $('input[name="authorizedQuantity"]').val();
                                        }else if($('input[name="lineOfCredit"]').val()){
                                            item.amount = $('input[name="lineOfCredit"]').val();
                                        }else {
                                            item.number = '';
                                            item.amount = ''
                                        }
                                        item.colsIsShow = true;
                                    });

                                    addPermissionsGroupFormTbData = [...addPermissionsGroupFormTbData , ...checkStatus.data];

                                    table.reload('addPermissionsGroupFormTable', {data: addPermissionsGroupFormTbData});
                                    layer.close(addRestrictedMaterialsPopUp);
                                });

                                // 搜索
                                form.on('submit(addRestrictedMaterialsFormSearch)', function (data) {
                                    addRestrictedMaterialsFormTb.reload({where: data.field,page: {curr: 1}},'data');
                                });

                            }


                        });
                    }

                    function isShowTable(_type){
                        if(_type === 'unlimited' || _type === 'unlimitedQuantity'){
                            addPermissionsGroupFormTbData = [];
                            table.reload('addPermissionsGroupFormTable', {data: addPermissionsGroupFormTbData});
                        }else if(_type === 'noAstrict'){
                            addPermissionsGroupFormTbData = [];
                            table.reload('addPermissionsGroupFormTable', {data: addPermissionsGroupFormTbData});
                        }else if(_type === 'materiel' || _type === 'category'){
                            addPermissionsGroupFormTbData = [];
                            table.reload('addPermissionsGroupFormTable', {data: addPermissionsGroupFormTbData});
                        }

                    }
                    if(data){
                        data.status = data.status == 0 ? 'on' : '';
                        restrictWayFn(data.astrictMaterial);

                        if(data.creditWay =='unlimitedQuantity' || data.creditWay === 'unlimited'){
                            addPermissionsGroupAddFn(data.creditWay);
                            materialIdBox(data.creditWay);
                            restrictWayFn(data.creditWay)
                        }else {
                            addPermissionsGroupAddFn(data.restrictWay);
                            materialIdBox(data.restrictWay);
                        }

                        if (_type == 'details') {
                            $('[lay-filter="addPermissionsGroupForm"] input').attr('disabled', 'disabled');
                            $('[lay-filter="addPermissionsGroupForm"] select').attr('disabled', 'disabled');
                            $('[lay-filter="addPermissionsGroupForm"] input').css('borderColor', 'transparent');
                            $('button[lay-filter="addPermissionsGroupFormSubmit"]').remove();
                            $('#addPermissionsGroupAdd').remove();
                        } else {
                            $('form[lay-filter="addPermissionsGroupForm"]  input[name="name"]').attr('disabled', 'disabled');

                            //添加限制物料
                            $('#addPermissionsGroupAdd').click(function () {
                                addPermissionsGroupAddPup();
                            });

                            form.on('submit(addPermissionsGroupFormSubmit)', function (d) {
                                let authorityMaterielList = [];
                                addPermissionsGroupFormTbData.forEach(item=>{
                                    let obj = {};
                                    obj.skuCode = item.skuCode;
                                    obj.id = item.id;
                                    obj.categoryId = item.productCategoryId;

                                    obj.manageld = '';
                                    if(d.field.lineOfCredit && d.field.lineOfCredit > 0){
                                        obj.amount = item.amount;
                                    }else {
                                        obj.number = item.number
                                    }
                                    authorityMaterielList.push(obj)
                                });
                                layer.load(2);
                                d.field.cabinetId = cabinetData.id;
                                d.field.cabinetCode = cabinetData.cabCode;
                                d.field.status = d.field.status == 'on' ? 0 : 1;
                                d.field.authorityMaterielList = authorityMaterielList;

                                admin.req('enterprisecab/wcabinet/admin/wauthorityManage/update', JSON.stringify(d.field), function (res) {
                                    layer.closeAll('loading');
                                    if (res.code == 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('mainCabinetAuthorityTable');
                                        layer.close(addPermissionsGroupPopUp);
                                    } else {
                                        layer.msg(res.msg, {icon: 2});
                                    }
                                }, 'PUT', true, 'application/json; charset=utf-8');
                                return false
                            });
                        }


                        form.val('addPermissionsGroupForm', data);
                        selectedDataExt(arr2treeExt, data.materialId);
                        smlSelectInstansExt.setValue(data.materialId.split(","));


                        authorityManageId = data.id;

                        admin.req('enterprisecab/wcabinet/admin/wauthorityManage/findMateriel',{ids,categoryIds,authorityManageId},res=>{
                            if(res.code === 200){
                                res.data.forEach(item=>{
                                    if(data.restrictWay == 'materiel' && _type == 'modify'){
                                        item.colsIsShow = true;
                                    }
                                    addPermissionsGroupFormTbData.push(item)

                                });

                                table.reload('addPermissionsGroupFormTable', {data: addPermissionsGroupFormTbData});
                            }
                        });



                    }else {

                        //添加限制物料
                        $('#addPermissionsGroupAdd').click(function () {
                            addPermissionsGroupAddPup();
                        });
                        form.on('submit(addPermissionsGroupFormSubmit)', function (d) {
                            let authorityMaterielList = [];
                            addPermissionsGroupFormTbData.forEach(item=>{
                                let obj = {};
                                obj.skuCode = item.skuCode;
                                obj.categoryId = item.productCategoryId;

                                obj.manageld = '';
                                if(d.field.lineOfCredit){
                                    obj.amount = item.amount;
                                }else {
                                    obj.number = item.number
                                }
                                authorityMaterielList.push(obj)
                            });
                            layer.load(2);
                            d.field.cabinetId = cabinetData.id;
                            d.field.cabinetCode = cabinetData.cabCode;
                            d.field.status = d.field.status == 'on' ? 0 : 1;
                            d.field.authorityMaterielList = authorityMaterielList;

                            admin.req('enterprisecab/wcabinet/admin/wauthorityManage/add', JSON.stringify(d.field), function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    table.reload('mainCabinetAuthorityTable');
                                    layer.close(addPermissionsGroupPopUp);
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'POST', true, 'application/json; charset=utf-8');
                            return false
                        });
                    }
                    form.render();
                }
            })
        }

        /*权限 --》成员管理*/
        function showMemberForm(data) {
            admin.open({
                type: 1,
                area: ['1400px', '700px'],
                offset: '75px',
                title: '设备权限组成员管理',
                content: $('#memberForm').html(),
                success: function (_data) {
                    let permissionsData = data;
                    let memberFormTB = table.render({
                        elem: '#memberFormTable',
                        title: '设备权限组成员管理',
                        url: config.base + 'enterprisecab/wcabinet/admin/wauthorityMember/list?authorityManageId=' + data.id,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'checkbox'}
                            , {field: 'userName', title: '成员姓名'}
                            , {field: 'jobNumber', title: '工号'}
                            , {field: 'phone', title: '电话'}
                            , {field: 'enterpriseName', title: '所属公司'}
                            , {field: 'deptName', title: '所属部门'}
                            , {field: 'positionName', title: '所属岗位'}
                            , {field: '', title: '所属权限组(以主柜面板为单位)', templet: d => data.name}
                            , {field: 'isDeleted', title: '状态', templet: d => d.isDeleted ? '正常' : '禁用'}
                            , {field: 'createTime', title: '创建时间'}
                            , {field: 'creatorName', title: '添加人'}
                            , {toolbar: '#memberFormTableBar', title: '操作'}
                        ]],
                    });

                    // 工具条点击事件
                    table.on('tool(memberFormTable)', function (obj) {
                        let data = obj.data;
                        if (obj.event === 'details') { //详情
                            showAddPermissionGroupMembersForm('details', Object.assign(permissionsData, data));
                        } else if (obj.event === 'delete') {  //删除
                            layer.confirm('确定要删除吗？', {
                                offset: '65px',
                                skin: 'layui-layer-admin'
                            }, function (i) {
                                layer.close(i);
                                layer.load(2);
                                admin.req('enterprisecab/wcabinet/admin/wauthorityMember/' + data.id, {}, res => {
                                    layer.closeAll('loading');
                                    if (res.code == 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('memberFormTable');
                                    } else {
                                        layer.msg(res.msg, {icon: 2});
                                    }
                                }, 'DELETE')
                            });
                        }
                    });


                    $('#memberFormBatchDeletion').click(function () { // 批量操作
                        let checkRows = table.checkStatus('memberFormTable');
                        if (checkRows.data.length == 0) {
                            layer.msg('请选择要删除的数据', {icon: 2});
                        } else {
                            new Promise((resolve, reject) => {
                                let ids = '';
                                checkRows.data.forEach(item => {
                                    ids += item.id + ','
                                });
                                resolve(ids.substr(0, ids.length - 1));
                            }).then(rData => {
                                layer.load(2);
                                admin.req('enterprisecab/wcabinet/admin/wauthorityMember/batchIds', {ids: rData.split(',')}, res => {
                                    layer.closeAll('loading');
                                    if (res.code == 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('memberFormTable');
                                    } else {
                                        layer.msg(res.msg, {icon: 2});
                                    }
                                }, 'DELETE')
                            });
                        }
                    });
                    $('#addMembersBtn').click(function () { // 添加权限组成员
                        showAddPermissionGroupMembersForm('add', data)
                    });

                    $('#memberFormExport').click(function () {  //导出
                        let checkRows = table.checkStatus('memberFormTable');
                        if (checkRows.data.length == 0) {
                            layer.msg('请选择要导出的数据', {icon: 2});
                        } else {
                            table.exportFile(memberFormTB.config.id, checkRows.data, 'xls', memberFormTB.config.title)
                        }
                    });

                    //搜索
                    form.on('submit(memberFormSearch)', function (data) {
                        memberFormTB.reload({where: data.field, page: {curr: 1}}, 'data');
                    });

                }
            })
        }

        //  添加权限组成员
        function showAddPermissionGroupMembersForm(_type, data) {
            let addPermissionGroupMembersPopUp = admin.open({
                type: 1,
                area: ['1200px', '750px'],
                offset: '85px',
                title: _type === 'details' ? '权限组成员详情' : '添加权限组成员',
                content: $('#addPermissionGroupMembers').html(),
                success: function (_data) {
                    $('#addPermissionGroupMembersFormAuthorizedQuantityBox').hide();
                    $('#addPermissionGroupMembersFormAuthorizedQuantityBox>input[name="authorizedQuantity"]').val('');
                    $('#addPermissionGroupMembersFormLineOfCreditBox').hide();
                    $('#addPermissionGroupMembersFormLineOfCreditBox>input[name="authorizedQuantity"]').val('');
                    if (data.creditType == "money") {
                        if (data.creditWay == 'unlimited') {
                            $('#addPermissionGroupMembersFormLineOfCreditBox').hide()
                        } else {
                            $('#addPermissionGroupMembersFormLineOfCreditBox').show()
                        }
                    } else if (data.creditType == "quantity") {
                        if (data.creditWay == 'unlimitedQuantity') {
                            $('#addPermissionGroupMembersFormAuthorizedQuantityBox').hide()
                        } else {
                            $('#addPermissionGroupMembersFormAuthorizedQuantityBox').show()
                        }
                    }

                    if (data.astrictMaterial == 'noAstrict') {
                        $('#materialId1Box').hide()
                    } else {
                        $('#materialId1Box').show()
                    }


                    let enterpriseName = '', deptName = '', positionName = '', userName = '';

                    let arr2treeExt;
                    let selectedData = function (treeData, targetId) {
                        for (var k = 0; k < treeData.length; k++) {
                            var nodeId = treeData[k].id;
                            if (targetId == nodeId) {
                                treeData[k].selected = true;
                                return;
                            } else {
                                if (treeData[k].children && treeData[k].children != '') {
                                    selectedData(treeData[k].children, targetId);
                                }
                            }
                        }
                    };
                    // enterprise/product/admin/productCategory/list?limit=9999&enterprise=0&page=1
                    admin.req('enterprise/knife/admin/productCategoryKnife/list?limit=9999&enterprise=0&page=1', {}, function (res) {
                        for (let i = 0; i < res.data.length; i++) {
                            res.data[i].children = [];
                        }
                        arr2treeExt = xmSelect.arr2tree(res.data, "parentId", "id", "children", -1);
                    }, 'get', false);

                    let selectedDataExt = function (treeData, targetId) {
                        var ids = targetId.split(",");
                        for (var k = 0; k < treeData.length; k++) {
                            var nodeId = treeData[k].id;
                            for (var t = 0; t < ids.length; t++) {
                                if (ids[t] == nodeId) {
                                    treeData[k].selected = true;
                                    continue;
                                } else {
                                    if (treeData[k].children && treeData[k].children != '') {
                                        selectedData(treeData[k].children, ids[t]);
                                    }
                                }
                            }
                        }
                    };

                    if(data.materialId){
                        $('#materialId1Box').show()
                    }else {
                        $('#materialId1Box').hide()
                    }
                    if (_type === 'details') {
                        form.val('addPermissionGroupMembersForm', data);
                        selectedDataExt(arr2treeExt, data.materialId);
                        $('.addPermissionGroupMembersDetail').show();
                        $('#userIdBox').hide();
                        $('[lay-filter="addPermissionGroupMembersForm"] input').attr('disabled', 'disabled');
                        // $('[lay-filter="addPermissionGroupMembersForm"] select').attr('disabled', 'disabled');
                        $('[lay-filter="addPermissionGroupMembersForm"] input').css('borderColor', 'transparent');
                        $('[lay-filter="addPermissionGroupMembersForm"] input').css('', 'transparent');
                        $('button[lay-filter="addPermissionGroupMembersFormSubmit"]').hide();
                        // loadSelectHtmlNew('', data.deptName, 'deptId', '[lay-filter="addPermissionGroupMembersForm"]', 1);
                        // loadSelectHtmlNew('', data.enterpriseName, 'enterpriseId', '[lay-filter="addPermissionGroupMembersForm"]', 1);
                        // loadSelectHtmlNew('', data.positionName, 'positionId', '[lay-filter="addPermissionGroupMembersForm"]', 1);
                        // loadSelectHtmlNew('', data.userName, 'userId', '[lay-filter="addPermissionGroupMembersForm"]', 1)

                    } else {
                        data.remark = '';
                        data.jobNumber = '';
                        data.phone = '';
                        data.isDeleted = true;
                        form.val('addPermissionGroupMembersForm', data);
                        selectedDataExt(arr2treeExt, data.materialId);
                        /*admin.req('user/admin/companyInfo/list?limit=9999', {}, res => {
                            if (res.code == '200') {
                                loadSelectHtmlNew(res.data, '请选择企业', 'enterpriseId', '[lay-filter="addPermissionGroupMembersForm"]', 1)
                            }
                        }, 'GET');*/

                       /* form.on('select(enterpriseId)', function (data) {
                            if (data.value != '') {
                                admin.req('user/admin/department/list?limit=9999&companyInfoId=' + data.value, {}, res => {
                                    enterpriseName = data.elem[data.elem.selectedIndex].text;
                                    if (res.code == '200') {
                                        loadSelectHtmlNew(res.data, '请选择选择部门', 'deptId', '[lay-filter="addPermissionGroupMembersForm"]', 1);
                                        loadSelectHtmlNew('', '请选择岗位', 'positionId', '[lay-filter="addPermissionGroupMembersForm"]', 1);
                                        loadSelectHtmlNew('', '请选择人员', 'userId', '[lay-filter="addPermissionGroupMembersForm"]', 2);
                                        $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val('');
                                        $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val('')
                                    } else {
                                        layer.msg(res.msg, {icon: 2});
                                        loadSelectHtmlNew('', '请选择选择部门', 'deptId', '[lay-filter="addPermissionGroupMembersForm"]', 1);
                                        loadSelectHtmlNew('', '请选择岗位', 'positionId', '[lay-filter="addPermissionGroupMembersForm"]', 1);
                                        loadSelectHtmlNew('', '请选择人员', 'userId', '[lay-filter="addPermissionGroupMembersForm"]', 2);
                                        $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val('');
                                        $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val('')
                                    }
                                }, 'GET');
                            } else {
                                loadSelectHtmlNew('', '请选择选择部门', 'deptId', '[lay-filter="addPermissionGroupMembersForm"]', 1);
                                loadSelectHtmlNew('', '请选择岗位', 'positionId', '[lay-filter="addPermissionGroupMembersForm"]', 1);
                                loadSelectHtmlNew('', '请选择人员', 'userId', '[lay-filter="addPermissionGroupMembersForm"]', 2);
                                $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val('');
                                $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val('')
                            }

                        });

                        form.on('select(deptId)', function (data) {
                            deptName = data.elem[data.elem.selectedIndex].text;
                            if (data.value != '') {
                                admin.req('user/admin/role/list?limit=9999&departmentId=' + data.value, {}, res => {
                                    if (res.code == '200') {
                                        loadSelectHtmlNew(res.data, '请选择岗位', 'positionId', '[lay-filter="addPermissionGroupMembersForm"]', 1);
                                        loadSelectHtmlNew('', '请选择人员', 'userId', '[lay-filter="addPermissionGroupMembersForm"]', 2);
                                        $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val('');
                                        $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val('')
                                    } else {
                                        layer.msg(res.msg, {icon: 2});
                                    }
                                }, 'GET');
                            } else {
                                loadSelectHtmlNew('', '请选择岗位', 'positionId', '[lay-filter="addPermissionGroupMembersForm"]', 1);
                                loadSelectHtmlNew('', '请选择人员', 'userId', '[lay-filter="addPermissionGroupMembersForm"]', 2);
                                $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val('');
                                $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val('')
                            }
                        });

                        form.on('select(positionId)', function (data) {
                            positionName = data.elem[data.elem.selectedIndex].text;
                            if (data.value != '') {
                                admin.req('user/admin/user/getUserByPostId?limit=9999&postId=' + data.value, {}, res => {
                                    if (res.code == '200') {
                                        loadSelectHtmlNew(res.data, '请选择人员', 'userId', '[lay-filter="addPermissionGroupMembersForm"]', 2);
                                        $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val('');
                                        $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val('')
                                    } else {
                                        layer.msg(res.msg, {icon: 2});
                                    }
                                }, 'GET');
                            } else {
                                loadSelectHtmlNew('', '请选择人员', 'userId', '[lay-filter="addPermissionGroupMembersForm"]', 2);
                                $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val('');
                                $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val('')
                            }
                        });

                        form.on('select(userId)', function (data) {
                            userName = data.elem[data.elem.selectedIndex].text;
                            if (data.value != '') {
                                admin.req('enterprisecab/wcabinet/admin/wauthorityMember/getAuthorityMemberByUserId', {id: data.value,'cabinetId':cabinetId}, res => {
                                    if (res.code == '200') {
                                        $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val(res.data.data.phone);
                                        $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val(res.data.data.username)
                                    } else {
                                        layer.msg(res.msg, {icon: 2});
                                        $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val('');
                                        $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val('');
                                        $('form[lay-filter="addPermissionGroupMembersForm"] select[name="userId"]').val('');

                                        loadSelectHtmlNew([], '', 'enterpriseId', '[lay-filter="addPermissionGroupMembersForm"]', 1);
                                        loadSelectHtmlNew([], '', 'deptId', '[lay-filter="addPermissionGroupMembersForm"]', 1);
                                        loadSelectHtmlNew([], '', 'positionId', '[lay-filter="addPermissionGroupMembersForm"]', 1);
                                        form.render();
                                    }
                                }, 'GET');
                                let bringData = JSON.parse($(data.elem).find("option:selected").attr("data"));
                                let enterpriseData = [{id:bringData.companyInfoId,name:'暂无企业'}],
                                    deptData = [{id:bringData.departmentId,name:'暂无部门'}],
                                    positionData = [{id:'',name:'暂无岗位'}];

                                if(bringData.companyInfoName){
                                    enterpriseData = [{id:bringData.companyInfoId,name:bringData.companyInfoName}];
                                }
                                if(bringData.departmentName){
                                    deptData = [{id:bringData.departmentId,name:bringData.departmentName}]
                                }
                                if(bringData.roles.length > 0){
                                    positionData = [{id:bringData.roles[0].id,name:bringData.roles[0].name}] ;
                                }
                                loadSelectHtmlNew(enterpriseData, '', 'enterpriseId', '[lay-filter="addPermissionGroupMembersForm"]', 1);
                                loadSelectHtmlNew(deptData, '', 'deptId', '[lay-filter="addPermissionGroupMembersForm"]', 1);
                                loadSelectHtmlNew(positionData, '', 'positionId', '[lay-filter="addPermissionGroupMembersForm"]', 1);

                                $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val(bringData.phone);
                                $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val(bringData.username);

                                positionName = bringData.roles.length > 0?bringData.roles[0].name:'';
                                deptName = bringData.departmentName?bringData.departmentName:'';
                                enterpriseName = bringData.companyInfoName?bringData.companyInfoName:'';

                            } else {
                                loadSelectHtmlNew([], '', 'enterpriseId', '[lay-filter="addPermissionGroupMembersForm"]', 1);
                                loadSelectHtmlNew([], '', 'deptId', '[lay-filter="addPermissionGroupMembersForm"]', 1);
                                loadSelectHtmlNew([], '', 'positionId', '[lay-filter="addPermissionGroupMembersForm"]', 1);

                                $('form[lay-filter="addPermissionGroupMembersForm"] input[name="phone"]').val('');
                                $('form[lay-filter="addPermissionGroupMembersForm"] input[name="jobNumber"]').val('');

                                positionName = '';
                                deptName = '';
                                enterpriseName = ''
                            }

                        });*/

                        // 提交
                        let formDataList = new Map();
                        form.on('submit(addPermissionGroupMembersFormSubmit)', function (d) {
                            layer.load(2);
                            let pushDataList = [];
                            formDataList.forEach((value, key)=>{
                                let obj = {
                                    name: d.field.name,
                                    lineOfCredit: d.field.lineOfCredit,
                                    authorizedQuantity: d.field.authorizedQuantity,
                                    materialId:d.field.materialId,
                                    userId: value.id,
                                    enterpriseId:value.companyInfoId,
                                    deptId: value.departmentId,
                                    positionId:value.roles.length>0?value.roles[0].id:'',
                                    jobNumber:value.username,
                                    phone:value.phone,
                                    isDeleted: d.field.isDeleted=='on'?true:false,
                                    remark: d.field.remark,
                                    authorityManageId: data.id,
                                    userName : value.nickname,
                                    positionName : value.roles.length>0?value.roles[0].name:'',
                                    deptName : value.departmentName,
                                    enterpriseName : value.companyInfoName
                                }
                                pushDataList.push(obj)
                            });

                            admin.req('enterprisecab/wcabinet/admin/wauthorityMember/addBatch ', JSON.stringify(pushDataList), function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    table.reload('memberFormTable');
                                    layer.close(addPermissionGroupMembersPopUp);
                                    table.reload('mainCabinetAuthorityTable');
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'POST' , true, 'application/json; charset=utf-8');
                            return false
                        });


                        let userIdBox = xmSelect.render({
                            el: '#userIdBox',
                            filterable: true,
                            autoRow: true,
                            layVerify: 'required',
                            template({ item, sels, name, value }){
                                let roles = item.roles[0]?item.roles[0].name:"";
                                return  "<span class='colorBlack'>" + item.nickname + "</span><span style='font-weight: 600'>工号:</span>" +
                                    "<span class='colorBlack1'>" + item.username + "</span><span style='font-weight: 600'>电话:</span>" +
                                    "<span class='colorBlack1'>" + item.phone + "</span><span style='font-weight: 600'>岗位:</span>" +
                                    "<span class='colorBlack1'>" + roles+ "</span><span style='font-weight: 600'>部门:</span>" +
                                    "<span class='colorBlack1'>" + item.departmentName + "</span><span style='font-weight: 600'>企业:</span>" +
                                    "<span class='colorBlack1'>" + item.companyInfoName + "</span>";
                            },
                            filterMethod: function(val, item, index, prop){

                                if(item.username.toLowerCase().indexOf(val.toLowerCase()) != -1){//把value相同的搜索出来
                                    return true;
                                }

                                if(item.nickname.toLowerCase().indexOf(val.toLowerCase()) != -1){//名称中包含的搜索出来
                                    return true;
                                }
                                return false;//不知道的就不管了
                            },
                            prop: {
                                name: 'nickname',
                                value: 'id',
                            },
                            data: [],
                            on: function(data){
                                if (data.isAdd){
                                    admin.req('enterprisecab/cabinet/admin/authorityMember/getAuthorityMemberByUserId', {id: data.change[0].id,'cabinetId':cabinetId}, res => {
                                        if (res.code === 200){
                                            formDataList.set(data.change[0].id,data.change[0])
                                            $('input[name="enterpriseId"]')
                                        }else {
                                            let index = data.arr.findIndex(item => item.id === data.change[0].id);
                                            if(index != -1){data.arr.splice(index, 1);}
                                            layer.msg(res.msg, {icon: 2});
                                        }
                                    })
                                }else {
                                    formDataList.delete(data.change[0].id)
                                }
                            }
                        });

                        admin.req('user/admin/user/list',{limit : '9999'},res=>{
                            if (res.code === 200){
                                // loadSelectHtmlNew(res.data, '请选择人员', 'userId', '[lay-filter="addPermissionGroupMembersForm"]', 7);
                                userIdBox.update({data: res.data});
                            }else {
                                // loadSelectHtmlNew([], '请选择人员', 'userId', '[lay-filter="addPermissionGroupMembersForm"]', 7);
                                userIdBox.update({data: [],})
                            }
                        })

                    }
                    let smlSelectInstansExt = xmSelect.render({
                        el: '#materialId1',
                        model: {label: {type: 'text'}},
                        clickClose: true,
                        filterable: true,
                        disabled: true,
                        tree: {
                            show: true,
                            strict: false,
                            expandedKeys: [-1],
                        },
                        tips: '顶级分类',
                        prop: {
                            name: 'name',
                            value: 'id',
                            children: 'children'
                        },
                        data() {
                            //填充数据
                            return arr2treeExt;
                        },
                        on: function (data) {
                            let id = '';
                            for (var j = 0; j < data.arr.length; j++) {
                                if (j == 0) {
                                    id = data.arr[j].id
                                } else {
                                    id += ',' + data.arr[j].id;
                                }
                            }
                            $("form[lay-filter='addPermissionGroupMembersForm'] input[name='materialId']").val(id)
                        }
                    });


                    form.render("select");
                    form.render("checkbox");
                }
            })
        }
    });
</script>